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

Refactored code to access TLS only in case of panic (II) #34866

Merged
merged 3 commits into from
Aug 11, 2016

Conversation

nikhilshagri
Copy link
Contributor

Fixes #34787
r? @alexcrichton
Do it very carefully this time!

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@nikhilshagri nikhilshagri changed the title Refactored code to access TLS only in case of panic Refactored code to access TLS only in case of panic (II) Jul 16, 2016
@alexcrichton
Copy link
Member

@bors: r+ 0ab8e0e

Thanks, and sorry about that!

@nikhilshagri
Copy link
Contributor Author

No problem!

Manishearth added a commit to Manishearth/rust that referenced this pull request Jul 17, 2016
…richton

Refactored code to access TLS only in case of panic (II)

Fixes rust-lang#34787
r? @alexcrichton
Do it **very** carefully this time!
@bors
Copy link
Contributor

bors commented Jul 17, 2016

⌛ Testing commit 0ab8e0e with merge 921eadd...

@Manishearth
Copy link
Member


failures:

---- [run-pass] run-pass\panic-recover-propagate.rs stdout ----

error: test run failed!
status: exit code: 3221225725
command: PATH="C:\bot\slave\auto-win-gnu-32-opt-rustbuild\build\obj\build\i686-pc-windows-gnu\stage2\lib\rustlib\i686-pc-windows-gnu\lib;C:\bot\slave\auto-win-gnu-32-opt-rustbuild\build\obj\build\i686-pc-windows-gnu\stage2-tools\i686-pc-windows-gnu\release\deps;C:\bot\slave\auto-win-gnu-32-opt-rustbuild\build\obj\build\i686-pc-windows-gnu\stage2-rustc\i686-pc-windows-gnu\release\deps;C:\bot\slave\auto-win-gnu-32-opt-rustbuild\build\obj\build\i686-pc-windows-gnu\stage2-test\i686-pc-windows-gnu\release\deps;C:\bot\slave\auto-win-gnu-32-opt-rustbuild\build\obj\build\i686-pc-windows-gnu\stage2-std\i686-pc-windows-gnu\release\deps;C:\mingw-w64\i686-4.9.1-win32-dwarf-rt_v3-rev1\mingw32\bin;C:\Python27;C:\msys64\mingw32\bin;C:\msys64\usr\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\msys64\usr\bin;C:\python27;C:\python27\scripts;C:\program files (x86)\inno setup 5;C:\program files (x86)\CMake\bin;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit;C:\Program Files\Microsoft SQL Server\110\Tools\Binn;C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0" C:\bot\slave\auto-win-gnu-32-opt-rustbuild\build\obj\build\i686-pc-windows-gnu\test\run-pass\panic-recover-propagate.stage2-i686-pc-windows-gnu.exe 
stdout:
------------------------------------------

------------------------------------------
stderr:
------------------------------------------

thread '<unknown>' has overflowed its stack

------------------------------------------

thread '[run-pass] run-pass\panic-recover-propagate.rs' panicked at 'explicit panic', C:\bot\slave\auto-win-gnu-32-opt-rustbuild\build\src\tools\compiletest\src\runtest.rs:2243
note: Run with `RUST_BACKTRACE=1` for a backtrace.


failures:
    [run-pass] run-pass\panic-recover-propagate.rs

test result: FAILED. 2459 passed; 1 failed; 14 ignored; 0 measured



command did not execute successfully: "C:\\bot\\slave\\auto-win-gnu-32-opt-rustbuild\\build\\obj\\build\\i686-pc-windows-gnu\\stage2-tools\\i686-pc-windows-gnu\\release\\compiletest.exe" "--compile-lib-path" "C:\\bot\\slave\\auto-win-gnu-32-opt-rustbuild\\build\\obj\\build\\i686-pc-windows-gnu\\stage2\\bin" "--run-lib-path" "C:\\bot\\slave\\auto-win-gnu-32-opt-rustbuild\\build\\obj\\build\\i686-pc-windows-gnu\\stage2\\lib\\rustlib\\i686-pc-windows-gnu\\lib" "--rustc-path" "C:\\bot\\slave\\auto-win-gnu-32-opt-rustbuild\\build\\obj\\build\\i686-pc-windows-gnu\\stage2\\bin\\rustc.exe" "--rustdoc-path" "C:\\bot\\slave\\auto-win-gnu-32-opt-rustbuild\\build\\obj\\build\\i686-pc-windows-gnu\\stage2\\bin\\rustdoc.exe" "--src-base" "C:\\bot\\slave\\auto-win-gnu-32-opt-rustbuild\\build\\src/test\\run-pass" "--build-base" "C:\\bot\\slave\\auto-win-gnu-32-opt-rustbuild\\build\\obj\\build\\i686-pc-windows-gnu\\test\\run-pass" "--stage-id" "stage2-i686-pc-windows-gnu" "--mode" "run-pass" "--target" "i686-pc-windows-gnu" "--host" "i686-pc-windows-gnu" "--llvm-filecheck" "C:\\bot\\slave\\auto-win-gnu-32-opt-rustbuild\\build\\obj\\build\\i686-pc-windows-gnu\\llvm\\build\\bin\\FileCheck.exe" "--host-rustcflags" "-Crpath -O" "--target-rustcflags" "-Crpath -O -Lnative=C:\\bot\\slave\\auto-win-gnu-32-opt-rustbuild\\build\\obj\\build\\i686-pc-windows-gnu\\rust-test-helpers" "--docck-python" "python" "--lldb-python" "python" "--gdb-version" "GNU gdb (GDB) 7.8" "--cc" "" "--cxx" "" "--cflags" "" "--llvm-components" "" "--llvm-cxxflags" "" "--adb-path" "adb" "--adb-test-dir" "/data/tmp" "--android-cross-path" ""
expected success, got: exit code: 101

https://buildbot.rust-lang.org/builders/auto-win-gnu-32-opt-rustbuild/builds/1785/steps/test/logs/stdio

@bors
Copy link
Contributor

bors commented Jul 17, 2016

💔 Test failed - auto-win-gnu-32-opt-rustbuild

@nikhilshagri
Copy link
Contributor Author

This might be occurring because when this panic is thrown, another panic already exists.

@alexcrichton
Copy link
Member

Hm although in that case wouldn't catch_unwind set the panic count to 0, and then the resume_unwind would bump it back up to 1?

@nikhilshagri
Copy link
Contributor Author

Updated PR as per discussion on IRC.

@alexcrichton
Copy link
Member

@bors: r+ b36ae59a1b5d5ea3e3dd9b3e48c1c40fc6f002e8

Thansk!

@bors
Copy link
Contributor

bors commented Jul 21, 2016

⌛ Testing commit b36ae59 with merge 777ed5a...

@bors
Copy link
Contributor

bors commented Jul 21, 2016

💔 Test failed - auto-linux-64-cargotest

@alexcrichton
Copy link
Member

@bors: retry

On Wed, Jul 20, 2016 at 5:47 PM, bors notifications@github.com wrote:

💔 Test failed - auto-linux-64-cargotest
https://buildbot.rust-lang.org/builders/auto-linux-64-cargotest/builds/1190


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#34866 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAD95OH5XPj5oO6BVZC2hgUamB3mblB4ks5qXsGVgaJpZM4JOGBV
.

@bors
Copy link
Contributor

bors commented Jul 21, 2016

⌛ Testing commit b36ae59 with merge 886f1d4...

@bors
Copy link
Contributor

bors commented Jul 21, 2016

💔 Test failed - auto-win-msvc-64-opt-mir

@alexcrichton
Copy link
Member

@bors: retry

sorry for the number of retries...

On Thu, Jul 21, 2016 at 12:26 PM, bors notifications@github.com wrote:

💔 Test failed - auto-win-msvc-64-opt-mir
https://buildbot.rust-lang.org/builders/auto-win-msvc-64-opt-mir/builds/1500


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#34866 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAD95OFdEVyLTEuDVm0QiE-D9rCtGkChks5qX8f8gaJpZM4JOGBV
.

@bors
Copy link
Contributor

bors commented Jul 22, 2016

⌛ Testing commit b36ae59 with merge 3df4e9a...

@bors
Copy link
Contributor

bors commented Jul 22, 2016

💔 Test failed - auto-win-gnu-32-opt-rustbuild

@alexcrichton
Copy link
Member

Hm last few bits of the message --

test fs::tests::recursive_rmdir ... ok


command did not execute successfully: "C:\\bot\\slave\\auto-win-gnu-32-opt-rustbuild\\build\\obj\\build\\i686-pc-windows-gnu\\stage0/bin\\cargo.exe" "test" "-j" "8" "--target" "i686-pc-windows-gnu" "--release" "--manifest-path" "C:\\bot\\slave\\auto-win-gnu-32-opt-rustbuild\\build\\src/rustc/std_shim\\Cargo.toml" "--features" " jemalloc" "-p" "std_shim" "-p" "alloc" "-p" "alloc_system" "-p" "build_helper" "-p" "collections" "-p" "core" "-p" "libc" "-p" "panic_abort" "-p" "panic_unwind" "-p" "rand" "-p" "rustc_unicode" "-p" "std" "-p" "unwind"
expected success, got: exit code: 3221225477


thread '<unnamed>' panicked at 'explicit panic', C:\bot\slave\auto-win-gnu-32-opt-rustbuild\build\src\libstd\io\buffered.rs:1109
note: Run with `RUST_BACKTRACE=1` for a backtrace.
fatal runtime error: failed to initiate panic, error 5

Looks suspicious, but also perhaps #33434, so I'm gonna retry and see what happens. If it passes on Travis it should pass on bors for a patch like this I think...

@bors: retry

@nikhilshagri
Copy link
Contributor Author

@alexcrichton I looked at the source code where this error occurred, and I think two panics are thrown there,which was ok before this patch. but now that we can't throw two panics at once, this runtime error might be occurring.

@alexcrichton
Copy link
Member

Oh really? This is the panic, right? I couldn't find a second...

@alexcrichton
Copy link
Member

Interesting! Did you configure your local checkout with --enable-debug-assertions? That may be why I wasn't reproducing on my end.

I think that also means that my hunch from before was correct. When this test panics, it panic with the standard library's machinery that's being tested. The actual panic, however, is then caught with another standard library. The standard library catching the panic did not have its PANIC_COUNT reset.

This somehow means that we need to deduplicate the panicking mechanisms here. I think the easiest thing to do would be:

  • Add #[cfg(not(test))] to the definition of the panic macro in src/libstd/macros.rs
  • Add #[macro_reexport(panic)] to the realstd extern crate declaration in src/libstd/lib.rs

That means that panics during testing should panic through the original standard library.

Again though the easiest thing to do is to just move this test out of the standard library, which should allow this PR to land.

@nikhilshagri
Copy link
Contributor Author

Interesting! Did you configure your local checkout with --enable-debug-assertions?

Yes, @eddyb recommended me to add them. They turned out to be useful after all!

Again though the easiest thing to do is to just move this test out of the standard library

This would be a bad idea imo, because there might be other tests where this might be happening. The other solution which you suggested (adding attributes) looks cleaner.

@alexcrichton
Copy link
Member

Ok, wanna give that a spin and see if it works?

Also this reminds me why it was failing on the bots, they all enable debug assertions!

@nikhilshagri
Copy link
Contributor Author

Well, turns out adding those attributes also brings in a ton of new errors while testing 😅. Think I will move the test for now and see what happens.

@nikhilshagri
Copy link
Contributor Author

How should I move the code inside run-pass? Should I just move the content inside a main function? And what about the panic?

@alexcrichton
Copy link
Member

Yeah just throwing it into a src/test/run-pass test should be fine, and you can wrap the whole thing in a catch_panic for now as well. The test is basically just ensuring that we don't abort the process, which a catch_panic should be sufficient to prevent.

@nikhilshagri
Copy link
Contributor Author

Like I suspected, other tests are unable to initiate the panic too. Should I move all such tests into run-pass?

@alexcrichton
Copy link
Member

Hm what sort of magnitude of tests is it turning out to be? If it's a good number them it may be good to rethink the strategy here. This does mean that a failing test in libstd will perhaps have a very obscure error message, which is kinda unfortunate.

Could you gist the errors you were getting from the #[macro_reexport] stage?

@nikhilshagri
Copy link
Contributor Author

The process aborts after the first failed panic, so there's no way to determine the number. I will post the logs tomorrow, gotta sleep now :)

@nikhilshagri
Copy link
Contributor Author

@alexcrichton
Copy link
Member

grr I had a feeling it was going to amount to something like that. Ok I think that route may be a dead end. I also believe that this works today because the only global state for panics is the PANIC_COUNT counter, and the function just resets it to 0 no matter what.

Another though, let's try:

  • Add a function, bump_panic_count, to panicking.rs
  • Mark the function both as unstable and public. Reexport it from src/libstd/rt.rs next to the begin_panic and begin_panic_fmt reexports.
  • When we bump the panic counter, do this:
if cfg!(test) {
    ::realstd::rt::bump_panic_counter();
} else {
    bump_panic_counter();
}

I think all other modifications of the panic counter in theory also need to go through this kind of shim, but for now we can make just the increments go that route.

Does that make sense?

@nikhilshagri
Copy link
Contributor Author

Should I do this wherever the panic counter is modified?

@alexcrichton
Copy link
Member

I think we can get away with just increments, not reads and decrements, but yeah otherwise wherever the panic counter is incremented we'll need logic like that instead.

@nikhilshagri
Copy link
Contributor Author

I tried to using the function for increments, then for increments and decrements, and neither seem to work.:worried:

@alexcrichton
Copy link
Member

Hm ok, I tested out this patch and was able to get make check-stage2-std working. Could you try that out and see if it works for you?

@nikhilshagri
Copy link
Contributor Author

It passes!! 😱 🎉
I don't understand how though. Why did you change this part here?

@eddyb
Copy link
Member

eddyb commented Aug 10, 2016

@cynicaldevil that's because update_panic_count returns the "after" count instead of the "before" one.

@nikhilshagri
Copy link
Contributor Author

nikhilshagri commented Aug 10, 2016

@eddyb oh ok.

@alexcrichton
Copy link
Member

@bors: r+ ea2216c

@bors
Copy link
Contributor

bors commented Aug 11, 2016

⌛ Testing commit ea2216c with merge 695b3d8...

bors added a commit that referenced this pull request Aug 11, 2016
Refactored code to access TLS only in case of panic (II)

Fixes #34787
r? @alexcrichton
Do it **very** carefully this time!
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.

6 participants