Skip to content

Conversation

@okaris
Copy link

@okaris okaris commented Jun 2, 2025

This PR introduces significant improvements to the recws library:

Key Changes:

  • Replace basic logging with Go's slog package
  • Add channel-based connection synchronization
  • Improve keepalive mechanism with proper cleanup

Breaking Changes:

  • Removed NonVerbose flag in favor of slog.Logger interface
  • Changed connection handling in Dial() to properly wait for establishment

Most likely fixes all:
#57
#20
#43
#42
#39
#38
#20
#19
#61

@loeffel-io
Copy link
Member

loeffel-io commented Jun 2, 2025

Thanks, but we need a simple logger interface, for people who want to use another logger like uber zap or want to change the logging format etc.

And i don't understand why we dereference the rc logger everywhere?:

logger := rc.Logger
if logger == nil {
logger = slog.Default()
}

there should be a more elegant solution

@okaris
Copy link
Author

okaris commented Jun 2, 2025

Made a few changes to remedy that. The default is slog with a simple interface exposed for users to hook in their own loggers.

@loeffel-io
Copy link
Member

loeffel-io commented Jun 2, 2025

LGTM, please give me some time to review
Would be great when someone else also could test it

friendly ping @sknr

@okaris
Copy link
Author

okaris commented Jun 2, 2025

Sounds good, I’m in no rush, already using my fork for the time being. Thanks!

@sknr
Copy link
Contributor

sknr commented Jun 3, 2025

@loeffel-io Sure, will have a look at it.

Copy link
Contributor

@sknr sknr left a comment

Choose a reason for hiding this comment

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

@okaris First of all, thanks for your contribution. Your changes looks fine to me, I only found an issue regarding the SubscribeHandler, and some duplications during logging.

recws.go Outdated
}
if !rc.getNonVerbose() {
log.Printf("Dial: connect handler was successfully established with %s\n", rc.url)
rc.Logger.Error("connect handler failed", "error", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

@okaris Before your changes, the app exits with an error. I would suggest a similar behaviour if the SubscribeHandler fails, or at least triggering a CloseAndReconnect(). @loeffel-io Also the wording is a little bit confusing. SubscribeHandler but log message says connect handler. Let's stick to either one. What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

👍

recws.go Outdated
}
if err != nil {
rc.Logger.Error("write message error", "error", err)
rc.Logger.Info("closing connection and reconnecting")
Copy link
Contributor

Choose a reason for hiding this comment

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

You can remove this line, because of duplication in CloseAndReconnect()

recws.go Outdated
// Wait for either connection success or handshake timeout
select {
case <-connected:
rc.Logger.Info("connection established")
Copy link
Contributor

Choose a reason for hiding this comment

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

Can be removed since it duplicates logging message in line 470.

@loeffel-io
Copy link
Member

@sknr did you run a e2e test?

@sknr
Copy link
Contributor

sknr commented Jun 7, 2025

@sknr did you run a e2e test?

I didn’t write comprehensive end-to-end tests, but I did implement some basic tests to cover key scenarios like reconnection handling, handshake timeouts, and send/receive behavior. These helped me verify core functionality and also led me to identify issues like duplicated log messages.

@loeffel-io
Copy link
Member

ping @okaris

@okaris
Copy link
Author

okaris commented Jan 8, 2026

image

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.

3 participants