websocket icon indicating copy to clipboard operation
websocket copied to clipboard

fix: possible panic in client tests

Open alexandear opened this issue 6 months ago • 1 comments

What type of PR is this? (check all applicable)

  • [ ] Refactor
  • [ ] Feature
  • [x] Bug Fix
  • [ ] Optimization
  • [ ] Documentation Update
  • [ ] Go Version Update
  • [ ] Dependency Update

Description

This PR fixes a possible panic in tests. When err is not nil in newWebsocketServer, websocketServer is nil, and defer websocketServer.Close() will panic. The same applies to the newProxyServer function.

Added/updated tests?

  • [x] Yes
  • [ ] No, and this is why: please replace this line with details on why tests have not been included
  • [ ] I need help with writing tests

alexandear avatar Jul 04 '25 16:07 alexandear

The change in this PR is good.

This panic is not the only problem with an error return from the function newWebsocketServer. The function newWebsocketServer leaks a listener when returning an error. That function should websocketServer.Close() when returning an error.

ghost avatar Aug 30 '25 16:08 ghost