Skip to content

Conversation

@etodanik
Copy link

What?

Closes #4972

With a small caveat: I wasn't sure the proper implementation for wasClean and prefer to contribute it as a second later PR, after I get to read the RFC spec about it a bit more in depth.

Checklist

  • I have performed a self-review of my code.
  • I have commented on my code, particularly in hard-to-understand areas.
  • I have added tests for my changes.
  • I have run linter and tests locally (make check) and all pass.

@etodanik etodanik requested a review from a team as a code owner July 30, 2025 12:51
@etodanik etodanik requested review from inancgumus and mstoykov and removed request for a team July 30, 2025 12:51
@CLAassistant
Copy link

CLAassistant commented Jul 30, 2025

CLA assistant check
All committers have signed the CLA.

@etodanik
Copy link
Author

etodanik commented Aug 5, 2025

@mstoykov @inancgumus just clarifying if there's anything else I can help with, or is this good on track for release?
I see tests are failing, but they're rather flaky to begin with. They actually pass, but that whole test suite has leaks that are there regardless of this PR.

@mstoykov
Copy link
Contributor

mstoykov commented Aug 5, 2025

Hi @etodanik, thank you for the PR.

We are in the last week before releasing v1.2.0 - planned for next week. As such we are unlikely to be able to review this, within the week.

Looking at the CI - you probably should try to fix the lint issues. Also test are failing with races within the experimental websockets, while they weren't before. So you probably have introduced a race condition. Running test with -race locally might help you find the root cause and confirm that you have fixed.

I would argue both will need to be fixed before this is mergeable.

@etodanik
Copy link
Author

etodanik commented Aug 5, 2025

Hi @etodanik, thank you for the PR.

We are in the last week before releasing v1.2.0 - planned for next week. As such we are unlikely to be able to review this, within the week.

Looking at the CI - you probably should try to fix the lint issues. Also test are failing with races within the experimental websockets, while they weren't before. So you probably have introduced a race condition. Running test with -race locally might help you find the root cause and confirm that you have fixed.

I would argue both will need to be fixed before this is mergeable.

Ok. I'll attend to the linter stuff as well as the tests. However, I should note that even if I remove my tests and code completely , that whole test suite is flaky & fails half the time for me

@etodanik etodanik force-pushed the fix/ws-support-code-reason branch from 12e4a30 to 56162f7 Compare August 7, 2025 15:56
@etodanik
Copy link
Author

etodanik commented Aug 7, 2025

@mstoykov could we re-run CI/CD tasks? I fixed linter's complaints about long line & test flakiness.

@etodanik
Copy link
Author

etodanik commented Aug 7, 2025

Appreciate it. Hmm , I'll look at what the GH Action actually runs and make sure to get the same fails locally. Looks like I'm not catching the data race errors.

@etodanik
Copy link
Author

Alright, data race should be fixed now :)

@etodanik etodanik force-pushed the fix/ws-support-code-reason branch from da64c15 to eff0a6d Compare August 12, 2025 12:08
@etodanik
Copy link
Author

@mstoykov ready for another go at CI/CD :)

@etodanik etodanik force-pushed the fix/ws-support-code-reason branch from eff0a6d to 4a69c0b Compare August 13, 2025 15:45
@etodanik etodanik force-pushed the fix/ws-support-code-reason branch from 4a69c0b to df143bf Compare August 15, 2025 21:15
@etodanik
Copy link
Author

etodanik commented Aug 16, 2025

Rebased to master. Failing tests don't seem to be related to this PR code. (fails are in grpc and output)

Copy link
Contributor

@mstoykov mstoykov left a comment

Choose a reason for hiding this comment

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

I have left some comments, but will also need to read the RFC before a more in depth review.

defaultCloseHandler := conn.CloseHandler()
conn.SetCloseHandler(func(code int, text string) error {
close(closeReceived)
once.Do(func() { close(closeReceived) })
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this really necessary? I would expect we would've hit this over the years? Or is it just that this isn't used by anyone actually?

Comment on lines +749 to +764
rt := w.vu.Runtime()

if code != 0 && !isValidClientCloseCode(code) {
common.Throw(rt, fmt.Errorf(
"InvalidAccessError: Failed to execute 'close' on 'WebSocket': "+
"The close code must be either 1000, or between 3000 and 4999. %d is neither",
code,
))
}

if !isValidCloseReason(reason) {
common.Throw(rt, errors.New(
`SyntaxError: Failed to execute 'close' on 'WebSocket': The message must not be greater than 123 bytes`,
))
}

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 save yourself some trouble, by changing close to return an error and just returning it here without calling throw. It is used in two places, in the one you need to propagate the error in the other (the mapping ot the WebSocket Object) Sobek will do so for your

w.closeCode = code
w.closeReason = reason
}
_ = w.conn.Close()
Copy link
Contributor

Choose a reason for hiding this comment

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

Not certain why originally I didn't close this hsere, but request it happens elsewhere, but not certain this needs to be in this PR.

Did you have problems without this?

Copy link
Contributor

@mstoykov mstoykov left a comment

Choose a reason for hiding this comment

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

Hi @etodanik, just making certain you are aware we are waiting changes or comments on the previously brought up topics

@etodanik
Copy link
Author

etodanik commented Sep 4, 2025

Hi @etodanik, just making certain you are aware we are waiting changes or comments on the previously brought up topics

Ah, sorry, didn't catch the notification. I see it now! Will answer in the coming day or two !

@codebien codebien modified the milestones: v1.3.0, v1.4.0 Sep 11, 2025
@mstoykov
Copy link
Contributor

mstoykov commented Oct 9, 2025

Hi @etodanik it has been a month. I am going to close this PR now, and if you find the time to finish it, we will gladly look at new PR or you can comment here and I will reopen it.

Thank you for all the work so far 🙇

@mstoykov mstoykov closed this Oct 9, 2025
@etodanik
Copy link
Author

etodanik commented Oct 9, 2025 via email

@mstoykov mstoykov reopened this Oct 9, 2025
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.

websockets: Add reason, code and wasClean fields for close event

4 participants