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: libwaku's invalid waku message error handling #3301

Merged

Conversation

gabrielmer
Copy link
Contributor

@gabrielmer gabrielmer commented Feb 17, 2025

Description

Checking if required WakuMessage fields exist before trying to access them and returning an error in case they are not present in the message.

Additionally, fixing double dealloc in case of failure.

Changes

  • handling gracefully invalid messages in libwaku
  • fixing double dealloc

Issue

Copy link

github-actions bot commented Feb 17, 2025

You can find the image built from this PR at

quay.io/wakuorg/nwaku-pr:3301

Built from 7a3d2f2

@@ -297,7 +297,6 @@ proc waku_relay_publish(
jsonMessage = JsonMessage.fromJsonNode(jsonContent).valueOr:
raise newException(JsonParsingError, $error)
except JsonParsingError:
deallocShared(jwm)
Copy link
Member

Choose a reason for hiding this comment

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

Is jwm deallocated on finally, even if we have the return on line 302?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Good question. I think it should.
Nevertheless, @gabrielmer I think it is safer to use the defer approach in this case too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My understanding is that yes, but agree - let's use defer :)

@@ -297,7 +297,6 @@ proc waku_relay_publish(
jsonMessage = JsonMessage.fromJsonNode(jsonContent).valueOr:
raise newException(JsonParsingError, $error)
except JsonParsingError:
deallocShared(jwm)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Good question. I think it should.
Nevertheless, @gabrielmer I think it is safer to use the defer approach in this case too.

Copy link
Contributor

@NagyZoltanPeter NagyZoltanPeter left a comment

Choose a reason for hiding this comment

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

LGTM!!!

@gabrielmer gabrielmer merged commit a3876f1 into master Feb 17, 2025
10 of 12 checks passed
@gabrielmer gabrielmer deleted the chore-libwaku-handling-gracefully-invalid-message-formats branch February 17, 2025 16:37
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.

4 participants