Skip to content

Commit 8d9fcde

Browse files
committed
Add poll handler
1 parent a728958 commit 8d9fcde

File tree

13 files changed

+444
-280
lines changed

13 files changed

+444
-280
lines changed

cache.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,29 @@ type cache struct {
2020

2121
// value retrieves a value from cache if not expired.
2222
func (c *cache) value(key string) (any, bool) {
23-
c.mu.Lock()
24-
defer c.mu.Unlock()
25-
23+
c.mu.RLock()
2624
entry, exists := c.entries[key]
2725
if !exists {
26+
c.mu.RUnlock()
2827
return nil, false
2928
}
3029

31-
// Check expiration while holding the lock to prevent race condition
30+
// Check expiration while holding read lock
3231
if time.Now().After(entry.expiration) {
33-
// Remove expired entry
34-
delete(c.entries, key)
32+
c.mu.RUnlock()
33+
// Upgrade to write lock for deletion
34+
c.mu.Lock()
35+
// Double-check after lock upgrade to avoid race condition
36+
if e, exists := c.entries[key]; exists && time.Now().After(e.expiration) {
37+
delete(c.entries, key)
38+
}
39+
c.mu.Unlock()
3540
return nil, false
3641
}
3742

38-
return entry.value, true
43+
value := entry.value
44+
c.mu.RUnlock()
45+
return value, true
3946
}
4047

4148
// set stores a value in cache with TTL.

constants.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ const (
3535
classicTokenLength = 40 // Length of classic GitHub tokens.
3636
maxAppID = 999999999 // Maximum valid GitHub App ID.
3737
filePermSecure = 0o077 // Mask for checking secure file permissions.
38+
filePermReadOnly = 0o400 // Read-only file permissions.
39+
filePermOwnerRW = 0o600 // Owner read-write file permissions.
3840
maxGraphQLVarLength = 1000 // Maximum length for GraphQL variable strings.
3941
maxGraphQLVarNum = 1000000 // Maximum numeric value for GraphQL variables.
4042
maxURLLength = 500 // Maximum URL length to validate.
@@ -128,4 +130,7 @@ const (
128130
monthlyDaysThreshold = 30 // Days threshold for monthly activity
129131
bimonthlyDaysThreshold = 60 // Days threshold for bimonthly activity
130132
quarterlyDaysThreshold = 90 // Days threshold for quarterly activity
133+
134+
// Log safety constants.
135+
maxLogKeyLength = 100 // Maximum length for app key in logs
131136
)

0 commit comments

Comments
 (0)