Skip to content

Fix: Nil pointer panic in WriteMessageToSocket when WebSocket connection not found#3216

Merged
Umang01-hash merged 4 commits into
gofr-dev:developmentfrom
NitinKumar004:fix/nil-pointer-write-message-to-socket
Apr 7, 2026
Merged

Fix: Nil pointer panic in WriteMessageToSocket when WebSocket connection not found#3216
Umang01-hash merged 4 commits into
gofr-dev:developmentfrom
NitinKumar004:fix/nil-pointer-write-message-to-socket

Conversation

@NitinKumar004
Copy link
Copy Markdown
Contributor

@NitinKumar004 NitinKumar004 commented Mar 27, 2026

Summary

  • Added nil check for WebSocket connection in WriteMessageToSocket to return ErrConnectionNotFound instead of panicking when no connection exists in the context.
  • Added unit test for the nil connection scenario.

Fixes #3213

Test plan

  • Added TestContext_WriteMessageToSocket_NilConnection unit test
  • Linter passes with 0 issues
  • Existing tests still pass

GetConnectionFromContext can return nil when no WebSocket connection
exists in the context, causing a nil pointer panic. Add a nil check
to return ErrConnectionNotFound instead of panicking.

Fixes gofr-dev#3213
@NitinKumar004 NitinKumar004 force-pushed the fix/nil-pointer-write-message-to-socket branch from 315a516 to 5ef1f7a Compare March 27, 2026 12:04
@Umang01-hash Umang01-hash merged commit e735fea into gofr-dev:development Apr 7, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix: Nil pointer panic in WriteMessageToSocket when WebSocket connection not found

2 participants