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

feat: Supports callbacks when reading a message fails #331

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tttoad
Copy link

@tttoad tttoad commented Dec 27, 2024

see: #330

@tttoad tttoad requested a review from a team as a code owner December 27, 2024 07:32
Copy link

linux-foundation-easycla bot commented Dec 27, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: tttoad / name: ttoad (8335e42)

@tigrannajaryan
Copy link
Member

Where is the new callback used?

@tttoad
Copy link
Author

tttoad commented Jan 8, 2025

Where is the new callback used?

Sorry, missed submitting a file change.
PTAL.

@tigrannajaryan
Copy link
Member

tigrannajaryan commented Feb 7, 2025

This appears stale - no response on comments. (Nevermind, I failed to hit Publish button with my question).

This conflicts with other changes to callbacks. Please recreate if still relevant.

var (
errAlreadyStarted = errors.New("already started")
)
var errAlreadyStarted = errors.New("already started")
Copy link
Member

Choose a reason for hiding this comment

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

Please don't make irrelevant changes.

Copy link
Author

Choose a reason for hiding this comment

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

Done.

@@ -62,6 +62,9 @@ type ConnectionCallbacks struct {

// OnConnectionClose is called when the OpAMP connection is closed.
OnConnectionClose func(conn Connection)

// OnConnectionError is called when an error occurs while reading or serializing a message.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// OnConnectionError is called when an error occurs while reading or serializing a message.
// OnReadMessageError is called when an error occurs while reading or deserializing a message.

Copy link
Author

Choose a reason for hiding this comment

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

done.

defer conn.Close()

// Send a message to the Server.
err := conn.WriteMessage(websocket.TextMessage, []byte(""))
Copy link
Member

Choose a reason for hiding this comment

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

Include some payload to verify it gets delivered to the callback ,e.g.:

Suggested change
err := conn.WriteMessage(websocket.TextMessage, []byte(""))
err := conn.WriteMessage(websocket.TextMessage, []byte("abc"))

Copy link
Author

Choose a reason for hiding this comment

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

done.

eventually(t, func() bool { return rcvMsg.Load() != nil })
errInfo := rcvMsg.Load().(ErrorInfo)
assert.EqualValues(t, websocket.TextMessage, errInfo.mt)
assert.EqualValues(t, []byte(""), errInfo.msgByte)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
assert.EqualValues(t, []byte(""), errInfo.msgByte)
assert.EqualValues(t, []byte("abc"), errInfo.msgByte)

Copy link
Author

Choose a reason for hiding this comment

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

done.

if err != nil {
s.logger.Errorf(msgContext, "Cannot decode message from WebSocket: %v", err)
connectionCallbacks.OnReadMessageError(agentConn, mt, msgBytes, err)
Copy link
Member

Choose a reason for hiding this comment

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

In addition, do we want OnReadMessageError to return a bool/enum, indicating that the connection must be kept or terminated? This gives additional control to the callback owner, for example to inspect the error and decide that it doesn't want to keep receiving messages from clients that send invalid messages.

I would expect strict serves to prefer this behavior, since it is likely that a misbehaving client will keep misbehaving and we would rather cut the communication early.

Since we are introducing a new callback in the public API, I'd rather make it more universally useful for a more than one case if we can, not just for logging (at a cost of tiny extra complexity of returning and checking a value from callback).

@andykellr thoughts?

Copy link

codecov bot commented Feb 8, 2025

Codecov Report

Attention: Patch coverage is 70.37037% with 8 lines in your changes missing coverage. Please review.

Project coverage is 77.92%. Comparing base (2ecac8d) to head (1b1915e).

Files with missing lines Patch % Lines
server/serverimpl.go 65.21% 6 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #331      +/-   ##
==========================================
- Coverage   78.29%   77.92%   -0.37%     
==========================================
  Files          25       25              
  Lines        2386     2401      +15     
==========================================
+ Hits         1868     1871       +3     
- Misses        410      420      +10     
- Partials      108      110       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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.

2 participants