Skip to content

WebBrokerAPI: Guard channel reads with comma-ok pattern in WebBrokerApi receiver to prevent nil-message panics #1959

@coderabbitai

Description

@coderabbitai

Summary

In event-gateway/gateway-runtime/internal/connectors/receiver/websocket/broker_api_connector.go, the channel receives in inboundLoop (around line 406) and outboundLoop (around line 465) use the plain form (msg := <-conn.inbound / msg := <-conn.outbound). When teardown closes these channels, the receive returns a zero/nil value and subsequent dereferences (e.g., msg.Value) can panic.

Proposed Fix

Apply the comma-ok pattern to both receive sites so the loops exit cleanly when the channel is closed:

// inboundLoop
case msg, ok := <-conn.inbound:
    if !ok || msg == nil {
        return
    }

// outboundLoop
case msg, ok := <-conn.outbound:
    if !ok || msg == nil {
        return
    }

References

Raised by @senthuran16.

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions