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

fix(AbortSignal/fetch) fix AbortSignal.timeout, fetch lock behavior and fetch errors #6390

Merged
merged 2 commits into from
Oct 10, 2023

Conversation

cirospaciari
Copy link
Collaborator

@cirospaciari cirospaciari commented Oct 10, 2023

What does this PR do?

This fix fetch behavior on error cases, fix HTTP destroying too early causing missing parts/events not to be emitted, fix AbortSignal.timeout, fix proper closing/ending off fetch when aborted, and also fix the state of readable streams to be used not only empty.

Fix #6366

  • Documentation or TypeScript types (it's okay to leave the rest blank in this case)
  • Code changes

How did you verify your code works?

I wrote automated tests

struct us_internal_callback_t *internal_cb = (struct us_internal_callback_t *) timer;

struct kevent64_s event;
EV_SET64(&event, (uint64_t) (void*) internal_cb, EVFILT_TIMER, EV_DELETE, 0, 0, (uint64_t)internal_cb, 0, 0);
kevent64(internal_cb->loop->fd, &event, 1, NULL, 0, 0, NULL);

/* (regular) sockets are the only polls which are not freed immediately */
us_poll_free((struct us_poll_t *) timer, internal_cb->loop);
if(fallthrough){
us_free(timer);
Copy link
Collaborator

Choose a reason for hiding this comment

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

isn't there a scenario where:

  1. Timer is scheduled to run in the next tick
  2. Tick happens, but before timer happens, the timer is cancelled
  3. Timer is freed
  4. Callback for timer runs after the timer is freed, which becomes a use-after-free

Copy link
Collaborator Author

@cirospaciari cirospaciari Oct 10, 2023

Choose a reason for hiding this comment

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

today we call us_poll_free with just do:

void us_poll_free(struct us_poll_t *p, struct us_loop_t *loop) {
    loop->num_polls--;
    us_free(p);
}

so is safe to assume that we are not breaking any behavior only avoiding loop->num_polls--; because on fallthrough: true we dont increment num_pools, But will check this scenario.

@github-actions
Copy link
Contributor

@cirospaciari 7 files with test failures on bun-darwin-aarch64:

  • test/cli/install/bun-install.test.ts
  • test/integration/next/default-pages-dir/test/dev-server.test.ts
  • test/js/bun/test/test-test.test.ts
  • test/js/bun/util/filesink.test.ts
  • test/js/node/watch/fs.watch.test.ts
  • test/js/third_party/postgres/postgres.test.ts
  • test/js/third_party/prisma/prisma.test.ts

View test output

#17223e045ea72905db3043dd1d76d1fce6db9fab

@github-actions
Copy link
Contributor

@cirospaciari 6 files with test failures on linux-x64-baseline:

  • test/bundler/esbuild/splitting.test.ts
  • test/cli/install/bun-install.test.ts
  • test/js/bun/util/filesink.test.ts
  • test/js/node/watch/fs.watch.test.ts
  • test/js/third_party/postgres/postgres.test.ts
  • test/js/third_party/prisma/prisma.test.ts

View test output

#17223e045ea72905db3043dd1d76d1fce6db9fab

@github-actions
Copy link
Contributor

@cirospaciari 5 files with test failures on linux-x64:

  • test/bundler/esbuild/splitting.test.ts
  • test/cli/install/bun-install.test.ts
  • test/js/node/watch/fs.watch.test.ts
  • test/js/third_party/postgres/postgres.test.ts
  • test/js/third_party/prisma/prisma.test.ts

View test output

#17223e045ea72905db3043dd1d76d1fce6db9fab

@github-actions
Copy link
Contributor

@cirospaciari 10 files with test failures on bun-darwin-x64-baseline:

  • test/bundler/esbuild/splitting.test.ts
  • test/cli/install/bun-install.test.ts
  • test/js/bun/spawn/spawn-streaming-stdout.test.ts
  • test/js/bun/util/filesink.test.ts
  • test/js/node/fs/fs.test.ts
  • test/js/node/watch/fs.watchFile.test.ts
  • test/js/third_party/postgres/postgres.test.ts
  • test/js/third_party/prisma/prisma.test.ts
  • test/js/third_party/webpack/webpack.test.ts
  • test/js/web/timers/setTimeout.test.js

View test output

#17223e045ea72905db3043dd1d76d1fce6db9fab

@Jarred-Sumner Jarred-Sumner merged commit 6301778 into main Oct 10, 2023
15 of 20 checks passed
@Jarred-Sumner Jarred-Sumner deleted the ciro/abort-signal-timeout-fix branch October 10, 2023 02:56
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.

Bun.serve hang with CPU 100% load when AbortSignal.timeout is used
2 participants