fix(context): use parent context instead of Background() to allow proper cancellation

- Fixed delegate party event handler to use parent context with timeout
- Fixed message acknowledgment to use parent context
- Prevents orphan goroutines when session fails or party exits
- Resolves system crash after delegate party failure
This commit is contained in:
hailin 2025-12-06 06:36:34 -08:00
parent 3adc091140
commit 450163a94d
2 changed files with 8 additions and 5 deletions

View File

@ -247,7 +247,9 @@ func createSessionEventHandler(
// Automatically participate based on session type
go func() {
ctx := context.Background()
// Use parent context to allow proper cancellation
participateCtx, cancel := context.WithTimeout(ctx, 5*time.Minute)
defer cancel()
// Determine session type from event
if event.EventType == "session_created" {
@ -264,7 +266,7 @@ func createSessionEventHandler(
JoinToken: joinToken,
}
result, err := participateKeygenUC.Execute(ctx, input)
result, err := participateKeygenUC.Execute(participateCtx, input)
if err != nil {
logger.Error("Keygen participation failed",
zap.Error(err),
@ -285,7 +287,7 @@ func createSessionEventHandler(
zap.Int("share_size", len(result.ShareForUser)))
if err := messageRouter.SubmitDelegateShare(
ctx,
participateCtx,
event.SessionId,
partyID,
result.ShareForUser,
@ -316,7 +318,7 @@ func createSessionEventHandler(
// This will be passed through the session event or retrieved separately
}
result, err := participateSigningUC.Execute(ctx, input)
result, err := participateSigningUC.Execute(participateCtx, input)
if err != nil {
logger.Error("Signing participation failed",
zap.Error(err),

View File

@ -181,7 +181,8 @@ func (c *MessageRouterClient) SubscribeMessages(
// Send acknowledgment for the received message
go func(messageID, sessionIDStr, pID string) {
ackCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
// Use parent context to allow proper cancellation
ackCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
sid, _ := uuid.Parse(sessionIDStr)
if err := c.AcknowledgeMessage(ackCtx, messageID, sid, pID, true, ""); err != nil {