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: panicking when can't create runtime for block_on #2905

Merged
merged 5 commits into from
Sep 12, 2019

Conversation

bartlomieju
Copy link
Member

@bartlomieju bartlomieju commented Sep 10, 2019

No description provided.

@bartlomieju bartlomieju force-pushed the fix-panic_on_too_many_files branch from aeee807 to 6d03dc7 Compare September 10, 2019 15:24
@bartlomieju bartlomieju force-pushed the fix-panic_on_too_many_files branch from 6d03dc7 to 763e4f3 Compare September 11, 2019 19:00
@bartlomieju bartlomieju changed the title [WIP] fix: panicking on opening too many files fix: panicking when can't create runtime for block_on Sep 11, 2019
@bartlomieju
Copy link
Member Author

@ry after thorough reading of #2243 I can tell that the issue describes several different problems.

  1. panic and hang when "Too many open files" occurs during creation of new Tokio runtime for block_on method - this PR addresses it
  2. panics during execution of code inside block_on - this still isn't handled properly, basically Deno hans with message like:
thread 'tokio-runtime-worker-0' panicked at <some panic inside block_on>
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: Canceled', src/libcore/result.rs:999:5
thread '<unnamed>' panicked at 'unexpected state while aborting task: Complete', /Users/biwanczuk/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-threadpool-0.1.15/src/task/mod.rs:216:21
s

I'd prefer to addresses second point in a separate PR as I need to think a bit more on how to test that properly.

I'm not sure there's a reliable reproduction to test issue resolved in this PR, we were just to eager creating runtimes ¯_(ツ)_/¯

@bartlomieju
Copy link
Member Author

bartlomieju commented Sep 11, 2019

2. panics during execution of code inside block_on - this still isn't handled properly, basically Deno hans with message like:

Actually that might not be true, adding this test on master properly panics.

// cli/tokio_util.rs

#[cfg(test)]
mod tests {
  use super::*;
  use futures;

  #[test]
  #[allow(unreachable_code)]
  #[should_panic]
  fn test_block_on() {
    let fut = futures::future::lazy(|| {
      panic!("unexpected panic during block on");
      if false {
        return futures::future::err(());
      }
      futures::future::ok(1)
    });

    let r = block_on(fut);

    assert!(r.is_err());
  }
}

So I guess this should fix #2243 after all. There are of course other panics (most of them from unwraps I suppose) to be addressed but that's story for another big epic.

@ry
Copy link
Member

ry commented Sep 11, 2019

This patch seems fine, but I'm not sure what it's fixing. #2243 seems to be fixed already....

@bartlomieju
Copy link
Member Author

@ry this panic: #2243 (comment)

@ry
Copy link
Member

ry commented Sep 11, 2019

@bartlomieju are you able to reproduce that panic on v0.17 ? I can’t.

@bartlomieju
Copy link
Member Author

@ry:

v0.17.0

$ ulimit -n 44
$ RUST_BACKTRACE=full deno -r https://deno.land/std/testing/runner.ts
Download https://deno.land/std/testing/runner.ts
Compile https://deno.land/std/testing/runner.ts
thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 24, kind: Other, message: "Too many open files" }', src/libcore/result.rs:999:5
stack backtrace:
   0:        0x1083e7062 - std::panicking::take_hook::hb25650a43c7b4abc
   1:        0x1083e6d2b - std::panicking::take_hook::hb25650a43c7b4abc
   2:        0x1083e7850 - std::panicking::rust_panic_with_hook::h7d6a669f1a899680
   3:        0x1083e737d - std::panicking::begin_panic_fmt::h5340abefa09e06ca
   4:        0x1083e7269 - rust_begin_unwind
   5:        0x108412ac2 - core::panicking::panic_fmt::he11aece98ed722cd
   6:        0x109620ec3 - <arc_swap::Protection as core::convert::From<core::option::Option<&arc_swap::debt::Debt>>>::from::h427ca8060d312f50
   7:        0x1096f25e4 - <arc_swap::Protection as core::convert::From<core::option::Option<&arc_swap::debt::Debt>>>::from::h427ca8060d312f50
   8:        0x1095ef42f - <arc_swap::Protection as core::convert::From<core::option::Option<&arc_swap::debt::Debt>>>::from::h427ca8060d312f50
   9:        0x1095f3090 - <arc_swap::Protection as core::convert::From<core::option::Option<&arc_swap::debt::Debt>>>::from::h427ca8060d312f50
  10:        0x1083f6c4f - __rust_maybe_catch_panic
  11:        0x109601977 - <arc_swap::Protection as core::convert::From<core::option::Option<&arc_swap::debt::Debt>>>::from::h427ca8060d312f50
  12:        0x1083ca9be - __rust_alloc_zeroed
  13:        0x1083f5a9e - std::sys::unix::thread::Thread::new::h395dd3888e55e07a
  14:     0x7fff795cc2eb - _pthread_body
  15:     0x7fff795cf249 - _pthread_start
thread 'tokio-runtime-worker-1' panicked at 'called `Result::unwrap()` on an `Err` value: RecvError', src/libcore/result.rs:999:5
stack backtrace:
   0:        0x1083e7062 - std::panicking::take_hook::hb25650a43c7b4abc
   1:        0x1083e6d2b - std::panicking::take_hook::hb25650a43c7b4abc
   2:        0x1083e7850 - std::panicking::rust_panic_with_hook::h7d6a669f1a899680
   3:        0x1083e737d - std::panicking::begin_panic_fmt::h5340abefa09e06ca
   4:        0x1083e7269 - rust_begin_unwind
   5:        0x108412ac2 - core::panicking::panic_fmt::he11aece98ed722cd
   6:        0x1096214ac - <arc_swap::Protection as core::convert::From<core::option::Option<&arc_swap::debt::Debt>>>::from::h427ca8060d312f50
   7:        0x1096f3200 - <arc_swap::Protection as core::convert::From<core::option::Option<&arc_swap::debt::Debt>>>::from::h427ca8060d312f50
   8:        0x109692887 - <arc_swap::Protection as core::convert::From<core::option::Option<&arc_swap::debt::Debt>>>::from::h427ca8060d312f50
   9:        0x109696675 - <arc_swap::Protection as core::convert::From<core::option::Option<&arc_swap::debt::Debt>>>::from::h427ca8060d312f50
  10:        0x1096f4939 - <arc_swap::Protection as core::convert::From<core::option::Option<&arc_swap::debt::Debt>>>::from::h427ca8060d312f50
  11:        0x109083add - deno::isolate::Isolate::shared_isolate_handle::h757989c949f4c4f5
  12:        0x109029720 - core::task::wake::RawWaker::new::hb8bc634ea20c7569
  13:        0x1085dd43c - core::task::wake::RawWaker::new::hb8bc634ea20c7569
  14:        0x108585361 - core::task::wake::RawWaker::new::hb8bc634ea20c7569
  15:        0x108584a13 - core::task::wake::RawWaker::new::hb8bc634ea20c7569
fatal runtime error: failed to initiate panic, error 5
Abort trap: 6

this PR

$ ulimit -n 44
$ RUST_BACKTRACE=full deno_dev -r https://deno.land/std/testing/runner.ts
Download https://deno.land/std/testing/runner.ts
Compile https://deno.land/std/testing/runner.ts
error: Uncaught Other: Too many open files (os error 24)
► file:///Users/biwanczuk/dev/deno/js/dispatch_json.ts:40:11
    at DenoError (file:///Users/biwanczuk/dev/deno/js/errors.ts:20:5)
    at unwrapResponse (file:///Users/biwanczuk/dev/deno/js/dispatch_json.ts:40:11)
    at sendSync (file:///Users/biwanczuk/dev/deno/js/dispatch_json.ts:67:10)
    at fetchSourceFile (file:///Users/biwanczuk/dev/deno/js/compiler.ts:143:15)
    at _resolveModule (file:///Users/biwanczuk/dev/deno/js/compiler.ts:244:24)
    at getSourceFile (file:///Users/biwanczuk/dev/deno/js/compiler.ts:350:16)
    at findSourceFile (typescript.js:90560:29)
    at typescript.js:90459:85
    at getSourceFileFromReferenceWorker (typescript.js:90426:34)
    at processSourceFile (typescript.js:90459:13)

Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

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

Ok cool. thanks!

LGTM

@bartlomieju
Copy link
Member Author

Just one small change - I replaced unwraps on one-shot channel with expects. If those calls fail then there are really too few available files to properly run compiler.

@bartlomieju bartlomieju force-pushed the fix-panic_on_too_many_files branch from ed8c9e3 to 4e43e46 Compare September 11, 2019 23:26
@ry ry merged commit 6123191 into denoland:master Sep 12, 2019
@bartlomieju bartlomieju deleted the fix-panic_on_too_many_files branch September 12, 2019 06:42
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.

2 participants