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

Fix for messages coming from the message pool always ends up as non-confirmable #366

Merged
merged 4 commits into from
Sep 8, 2022

Conversation

andersroos
Copy link
Contributor

Hello!

While using this lib I discovered that observe requests sometimes wasn't retried properly (here). After a bit of digging I found out that messages coming from the message pool always are set to non-confirmable while new messages not coming from the pool are confirmable by default.

Since the blockwise code copies messages it can end up sending a non-confirmable message when the original message was actually set as confirmable.

I am not very familiar with this code base so I am not sure this fix is good, I have tested it with our server and it seems to solve the issue.

To me it feels wrong to assume what the type should be, so I guess it needs to be set every time a message is acquired? Regardless if it is reused or new? I haven't checked the reset of the code base to see if there are more places like this, just this file. In the meantime I use a message pool with 0 max size as a workaround since most messages should be conformable anyway, but that could cause other issues I suppose, I mean I assume that reset sets a message to non-confirmable for a reason.

Cheers and thanks for a good library!

@Danielius1922
Copy link
Member

(Seems OK to me, but I'll wait for Jozef to go over it. He's enjoying his holiday this week, so that'll have to wait for next week.)

@@ -889,6 +894,7 @@ func (b *BlockWise) processReceivedMessage(w ResponseWriter, r Message, maxSzx S
szx = getSzx(szx, maxSzx)
sendMessage := b.acquireMessage(r.Context())
sendMessage.SetToken(token)
// TODO What to set type to?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In v2 this is handled by:

if req.Options().HasOption(message.Block1) || req.Options().HasOption(message.Block2) {

and
return cc.blockWise.WriteMessage(cc.RemoteAddr(), req, cc.blockwiseSZX, cc.session.MaxMessageSize(), func(bwreq blockwise.Message) error {

for v3 this will be refactored to block-wise.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I don't really get this, how is it handled by those lines, can you help me understand? I mean eventually the execution reaches this code

func (cc *ClientConn) writeMessage(req *pool.Message) error {

and the message type is used to determine if there should be retries or not. So unless the type is set explicitly somewhere it will be random, Confirmable if it is a new message created in the message pool or it will be NonConfirmable if it is a reused message from the message pool.

net/blockwise/blockwise.go Outdated Show resolved Hide resolved
@andersroos
Copy link
Contributor Author

Thanks @jkralik! Is on a vacation trip at the moment, will take this up again when I am back home.

net/blockwise/blockwise.go Outdated Show resolved Hide resolved
@jkralik
Copy link
Member

jkralik commented Sep 8, 2022

@andersroos Pls could you resolve linter issue - https://github.com/plgd-dev/go-coap/actions/runs/3014872294 ? After that I will merge PR.

@andersroos
Copy link
Contributor Author

@andersroos Pls could you resolve linter issue - https://github.com/plgd-dev/go-coap/actions/runs/3014872294 ? After that I will merge PR.

Sure! Done.

@jkralik jkralik merged commit 44907dc into plgd-dev:master Sep 8, 2022
@jkralik
Copy link
Member

jkralik commented Sep 8, 2022

Great. Thx for contributing !

@andersroos andersroos deleted the fix-coap-lib branch September 8, 2022 13:59
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.

None yet

3 participants