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

The server crashes whenever I set server concurrency bigger than 1 #160

Closed
nicolaenicora opened this issue Aug 26, 2023 · 3 comments · Fixed by #161
Closed

The server crashes whenever I set server concurrency bigger than 1 #160

nicolaenicora opened this issue Aug 26, 2023 · 3 comments · Fixed by #161
Assignees
Labels
bug Something isn't working

Comments

@nicolaenicora
Copy link

nicolaenicora commented Aug 26, 2023

The server crashes whenever I set server concurrency bigger than 1

srv := &svc{ logger: logger, } frpcServer, err := echo.NewServer(srv, nil, &logger) if err != nil { logger.Fatal().Err(err) } frpcServer.SetConcurrency(2)

`
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x134af62]

goroutine 50 [running]:
github.com/loopholelabs/frisbee-go.(*Server).createHandler.func1(0x0)
/Users/GoLib/src/github.com/nnicora/fgrpc/vendor/github.com/loopholelabs/frisbee-go/server.go:245 +0x82
github.com/loopholelabs/frisbee-go.(*Server).handleLimitedPacket.func1(0x0)
/Users/GoLib/src/github.com/nnicora/fgrpc/vendor/github.com/loopholelabs/frisbee-go/server.go:388 +0x34
created by github.com/loopholelabs/frisbee-go.(*Server).handleLimitedPacket in goroutine 35
/Users/GoLib/src/github.com/nnicora/fgrpc/vendor/github.com/loopholelabs/frisbee-go/server.go:395 +0x498
Exiting.
`

Additional context
Debugging the server saw that the packet was nil and the err variable was 'connection closed'.
https://github.com/loopholelabs/frisbee-go/blob/staging/server.go#L395

@nicolaenicora nicolaenicora added the bug Something isn't working label Aug 26, 2023
@ShivanshVij
Copy link
Member

Okay so the bug seems to be that the p *packet.Packet on line https://github.com/loopholelabs/frisbee-go/blob/staging/server.go#L395C14-L395C15 happens to be nil.

p could only have been created here: https://github.com/loopholelabs/frisbee-go/blob/staging/server.go#L396 or here: https://github.com/loopholelabs/frisbee-go/blob/staging/server.go#L375, and in both places we're checking if err != nil

BUT, if err != nil here: https://github.com/loopholelabs/frisbee-go/blob/staging/server.go#L375, we don't return the function and let it continue: https://github.com/loopholelabs/frisbee-go/blob/staging/server.go#L378

So, the fix should just be as simple as properly checking if the connection should be closed, and then returning:

	p, err := frisbeeConn.ReadPacket()
	if err != nil {
		_ = frisbeeConn.Close()
		s.onClosed(frisbeeConn, err)
                 return
	}

@ShivanshVij
Copy link
Member

This also answers the question of why it only happens when concurrency > 1: https://github.com/loopholelabs/frisbee-go/blob/staging/server.go#L349, when concurrency < 2, we run handleUnlimitedPacket instead, and as you can see that one does call return on an error.

@ShivanshVij
Copy link
Member

ShivanshVij commented Aug 26, 2023

Closed as part of v0.7.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants