Skip to content
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

[BUG] panic when multiple events are set in empty namespace #102

Closed
heliosgo opened this issue Nov 17, 2023 · 0 comments
Closed

[BUG] panic when multiple events are set in empty namespace #102

heliosgo opened this issue Nov 17, 2023 · 0 comments

Comments

@heliosgo
Copy link
Contributor

Describe the bug
When multiple events are set in empty namespace, and include OnNativeMessage, it may panic if received native message before connectedNamespaces is set.

Screenshots
image

Here is some source code I found.

func (c *Conn) handleMessage(msg Message) error {
	if msg.isInvalid {
		return ErrInvalidPayload
	}

	if msg.IsNative && c.allowNativeMessages {
		ns := c.Namespace("")
		return ns.events.fireEvent(ns, msg)               // panic
	}

	......

	return nil
}

I think the code should be like this.

func (c *Conn) handleMessage(msg Message) error {
	if msg.isInvalid {
		return ErrInvalidPayload
	}

	if msg.IsNative && c.shouldHandleOnlyNativeMessages {    // this line
		ns := c.Namespace("")
		return ns.events.fireEvent(ns, msg)         
	}

	......

	return nil
}
heliosgo pushed a commit to heliosgo/neffos that referenced this issue Nov 17, 2023
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

No branches or pull requests

1 participant