-
Notifications
You must be signed in to change notification settings - Fork 400
fail any rpc call which blocks the runServer loop for more than 1s #1861
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e50fa3b
force debugname to be set
sawka 73f8429
add expmap. a synchronzied map with expiring keys
sawka e78d6d0
implement a once-per second debug log of 'slow clearing' rpcs. if rp…
sawka e1957f4
remove much logging from wshrouter
sawka a1e2ee9
streamtest command
sawka 430939f
a blank wsh test for testing
sawka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright 2025, Command Line Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var testCmd = &cobra.Command{ | ||
Use: "test", | ||
Hidden: true, | ||
Short: "test command", | ||
PreRunE: preRunSetupRpcClient, | ||
RunE: runTestCmd, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(testCmd) | ||
} | ||
|
||
func runTestCmd(cmd *cobra.Command, args []string) error { | ||
return nil | ||
} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// Copyright 2025, Command Line Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package ds | ||
|
||
import ( | ||
"sync" | ||
"time" | ||
|
||
"github.com/emirpasic/gods/trees/binaryheap" | ||
) | ||
|
||
// an ExpMap has "expiring" keys, which are automatically deleted after a certain time | ||
|
||
type ExpMap[T any] struct { | ||
lock *sync.Mutex | ||
expHeap *binaryheap.Heap // heap of expEntries (sorted by time) | ||
m map[string]expMapEntry[T] | ||
} | ||
|
||
type expMapEntry[T any] struct { | ||
Val T | ||
Exp time.Time | ||
} | ||
|
||
type expEntry struct { | ||
Key string | ||
Exp time.Time | ||
} | ||
|
||
func heapComparator(aArg, bArg any) int { | ||
a := aArg.(expEntry) | ||
b := bArg.(expEntry) | ||
if a.Exp.Before(b.Exp) { | ||
return -1 | ||
} else if a.Exp.After(b.Exp) { | ||
return 1 | ||
} | ||
return 0 | ||
} | ||
|
||
func MakeExpMap[T any]() *ExpMap[T] { | ||
return &ExpMap[T]{ | ||
lock: &sync.Mutex{}, | ||
expHeap: binaryheap.NewWith(heapComparator), | ||
m: make(map[string]expMapEntry[T]), | ||
} | ||
} | ||
|
||
func (em *ExpMap[T]) Set(key string, value T, exp time.Time) { | ||
em.lock.Lock() | ||
defer em.lock.Unlock() | ||
oldEntry, ok := em.m[key] | ||
em.m[key] = expMapEntry[T]{Val: value, Exp: exp} | ||
if !ok || oldEntry.Exp != exp { | ||
em.expHeap.Push(expEntry{Key: key, Exp: exp}) // this might create duplicates. that's ok. | ||
} | ||
} | ||
|
||
func (em *ExpMap[T]) expireItems_nolock() { | ||
// should already hold the lock | ||
now := time.Now() | ||
for { | ||
if em.expHeap.Empty() { | ||
break | ||
} | ||
// we know it isn't empty, so we ignore "ok" | ||
topI, _ := em.expHeap.Peek() | ||
top := topI.(expEntry) | ||
if top.Exp.After(now) { | ||
break | ||
} | ||
em.expHeap.Pop() | ||
entry, ok := em.m[top.Key] | ||
if ok && (entry.Exp.Before(now) || entry.Exp.Equal(now)) { | ||
delete(em.m, top.Key) | ||
} | ||
} | ||
} | ||
|
||
func (em *ExpMap[T]) Get(key string) (T, bool) { | ||
em.lock.Lock() | ||
defer em.lock.Unlock() | ||
em.expireItems_nolock() | ||
v, ok := em.m[key] | ||
return v.Val, ok | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Implement the actual test logic or remove placeholder code.
Returning
nil
suggests no operation performed. If the command is intended for testing system functionality, consider adding meaningful actions or removing the command to avoid confusion.