MCPcopy Create free account
hub / github.com/chainreactors/EvilProxy / waitForSession

Method waitForSession

internal/bridge/bridge.go:282–296  ·  view source on GitHub ↗

waitForSession waits for a session to appear, using channel-based notification. Returns nil if the session does not appear within the timeout.

(sessionID string, timeout time.Duration)

Source from the content-addressed store, hash-verified

280// waitForSession waits for a session to appear, using channel-based notification.
281// Returns nil if the session does not appear within the timeout.
282func (b *Bridge) waitForSession(sessionID string, timeout time.Duration) *sessions.Session {
283 if sess := sessions.Global().Get(sessionID); sess != nil {
284 return sess
285 }
286 ch, _ := b.sessionReady.LoadOrStore(sessionID, make(chan struct{}))
287 select {
288 case <-ch.(chan struct{}):
289 return sessions.Global().Get(sessionID)
290 case <-time.After(timeout):
291 log.Warnf("[bridge] waitForSession timeout for %s after %v", sessionID, timeout)
292 return nil
293 case <-b.ctx.Done():
294 return nil
295 }
296}
297
298// notifySessionReady signals any goroutines waiting for the given session.
299func (b *Bridge) notifySessionReady(sessionID string) {

Callers 1

Calls 2

GlobalFunction · 0.92
GetMethod · 0.45

Tested by 1