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

Improvements to WebSocket and ServerWebSocket #3257

Merged
merged 6 commits into from Jul 13, 2023
Merged

Improvements to WebSocket and ServerWebSocket #3257

merged 6 commits into from Jul 13, 2023

Conversation

Electroid
Copy link
Contributor

@Electroid Electroid commented Jun 9, 2023

import { serve } from "bun";

serve({
  fetch(request, server) {
    if (server.upgrade(request)) {
      return;
    }
    return new Response();
  },
  websocket: {
    open(ws) {
      ws.ping();
    },
    ping(ws, data) {
      ws.pong(data);
    },
    pong(ws, data) {
      ws.terminate();
    }
  }
});

New stuff

  • Default binaryType in WebSocket is now "nodebuffer" to match the server [breaking]
  • ws.terminate() - abruptly closes the connection
  • ws.ping(data?) - sends a ping
  • ws.pong(data?) - sends a pong

Bug fixes

  • ws.close(1000, "non-ascii") was not encoded properly
  • hostname and pathname were not encoded properly on WebSocket upgrade
  • idleTimeout could crash if between (0, 8] due to uws limitation

@Electroid Electroid added the enhancement New feature or request label Jun 9, 2023
@github-actions
Copy link

github-actions bot commented Jun 9, 2023

@Electroid prettier reported errors

[warn] test/js/bun/websocket/websocket-server.test.ts
[warn] test/js/first_party/ws/ws.test.ts
[warn] src/js/thirdparty/ws.js
[warn] Code style issues found in 3 files. Forgot to run Prettier?
error: "prettier" exited with code 1 (SIGHUP)
Checking formatting...

To one-off fix this manually, run:

bun fmt

You might need to run bun install locally and configure your text editor to auto-format on save.

#92ce42b2ca7bccacae9f5e1451c756d1072f08d9

@github-actions
Copy link

github-actions bot commented Jun 9, 2023

@Electroid 11 files with test failures on bun-darwin-aarch64:

  • test/bundler/bundler_compile.test.ts
  • test/cli/install/bun-link.test.ts
  • test/cli/install/bun-run.test.ts
  • test/cli/install/bunx.test.ts
  • test/js/bun/net/socket.test.ts
  • test/js/bun/spawn/spawn.test.ts
  • test/js/bun/test/test-test.test.ts
  • test/js/bun/util/unsafe.test.js
  • test/js/node/child_process/child_process-node.test.js
  • test/js/node/watch/fs.watch.test.ts
  • test/js/web/fetch/fetch-leak.test.js

View test output

#92ce42b2ca7bccacae9f5e1451c756d1072f08d9

@github-actions
Copy link

github-actions bot commented Jun 9, 2023

@Electroid 4 files with test failures on linux-x64:

  • test/cli/install/bun-link.test.ts
  • test/cli/install/bun-run.test.ts
  • test/js/node/watch/fs.watch.test.ts
  • test/js/web/fetch/fetch-leak.test.js

View test output

#92ce42b2ca7bccacae9f5e1451c756d1072f08d9

@github-actions
Copy link

github-actions bot commented Jun 9, 2023

@Electroid 4 files with test failures on linux-x64-baseline:

  • test/cli/install/bun-link.test.ts
  • test/cli/install/bun-run.test.ts
  • test/js/node/watch/fs.watch.test.ts
  • test/js/web/fetch/fetch-leak.test.js

View test output

#92ce42b2ca7bccacae9f5e1451c756d1072f08d9

@github-actions
Copy link

github-actions bot commented Jun 9, 2023

@Electroid 8 files with test failures on bun-darwin-x64-baseline:

  • test/cli/install/bun-link.test.ts
  • test/cli/install/bun-run.test.ts
  • test/js/bun/spawn/spawn-streaming-stdin.test.ts
  • test/js/bun/spawn/spawn.test.ts
  • test/js/bun/sqlite/sqlite.test.js
  • test/js/bun/util/sleepSync.test.ts
  • test/js/third_party/webpack/webpack.test.ts
  • test/js/web/timers/setTimeout.test.js

View test output

#92ce42b2ca7bccacae9f5e1451c756d1072f08d9

@paperdave
Copy link
Collaborator

is the binary type default on the global WebSocket client? because that kind of breaking change would break the web websocket spec- ideally those should match the browser

@Jarred-Sumner
Copy link
Collaborator

Jarred-Sumner commented Jun 9, 2023 via email

src/deps/uws.zig Outdated Show resolved Hide resolved
src/deps/uws.zig Outdated Show resolved Hide resolved
src/deps/uws.zig Outdated Show resolved Hide resolved
@Electroid Electroid linked an issue Jul 6, 2023 that may be closed by this pull request
@Electroid Electroid force-pushed the ws-ping-pong branch 2 times, most recently from 20c418b to b39fd3b Compare July 12, 2023 19:15
Copy link
Collaborator

@Jarred-Sumner Jarred-Sumner left a comment

Choose a reason for hiding this comment

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

LGTM after tests run

@Electroid
Copy link
Contributor Author

Looks like there's a flaky test with the websocket server, will take a look. (it's probably uws related)

@Electroid Electroid merged commit 9eb8eea into main Jul 13, 2023
11 of 13 checks passed
@Electroid Electroid deleted the ws-ping-pong branch July 13, 2023 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[bun] Warning: ws.WebSocket.ping() is not implemented in bun
3 participants