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

readSpecificJsonMessage can panic on queue overflow #3

Open
quadtrix opened this issue Aug 9, 2023 · 0 comments
Open

readSpecificJsonMessage can panic on queue overflow #3

quadtrix opened this issue Aug 9, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@quadtrix
Copy link
Owner

quadtrix commented Aug 9, 2023

In some cases readSpecificJsonMessage panics with the following error:

Delta Agent 0.1.-beta1
panic: runtime error: index out of range [1] with length 1

goroutine 23 [running]:
github.com/quadtrix/basicqueue.(*BasicQueue).readSpecificJsonMessage(0xc0001185a0, 0x1)
/home/nhtbrink/go/pkg/mod/github.com/quadtrix/basicqueue@v0.0.0-20230808074438-d245b21dd56b/basicqueue.go:548 +0x79f
github.com/quadtrix/basicqueue.(*BasicQueue).ReadJsonWithHistory(0xc0001185a0, {0xc0000b2000, 0x35}, {0xc00013afa0, 0x63, 0xaa?})
/home/nhtbrink/go/pkg/mod/github.com/quadtrix/basicqueue@v0.0.0-20230808074438-d245b21dd56b/basicqueue.go:633 +0x4bc
github.com/quadtrix/client_connector.(*ClientConnection).heartbeatSender(0xc0000ae000, 0x0?, 0x0?)
/home/nhtbrink/go/pkg/mod/github.com/quadtrix/client_connector@v0.0.0-20221009195911-96e8762ce08f/client_connector.go:531 +0x468
created by github.com/quadtrix/client_connector.New
/home/nhtbrink/go/pkg/mod/github.com/quadtrix/client_connector@v0.0.0-20221009195911-96e8762ce08f/client_connector.go:164 +0xafc

This is probably the scenario:

  • readSpecificJsonMessage is called and wants to read message nr 1 from a queue with 2 messages
  • checkForExpiry is running at the same time and removes message nr 0 from the same queue, making message nr 1 now message nr 0.
  • When the message needs to be retrieved for readSpecificJsonMessage, message nr 1 no longer exists and causes a panic since the read tries to read beyond the end of the queue

Probable solution:
Use queue locking for read actions as well as write actions.

@quadtrix quadtrix added the bug Something isn't working label Aug 9, 2023
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

When branches are created from issues, their pull requests are automatically linked.

1 participant