Bug 15104 – Switching fibers in finally blocks breaks EH

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
druntime
Product
D
Version
D2
Platform
x86
OS
All
Creation time
2015-09-23T22:37:00Z
Last change time
2015-10-04T18:19:23Z
Keywords
patch
Assigned to
nobody
Creator
code

Comments

Comment #0 by code — 2015-09-23T22:37:48Z
Consider the following test case: --- import core.thread : Fiber; void throwAndYield(string msg) { try { throw new Exception(msg); } finally { Fiber.yield(); } } void fiber(string name) { try { try { throwAndYield(name ~ ".1"); } finally { throwAndYield(name ~ ".2"); } } catch (Exception e) { assert(e.msg == name ~ ".1"); assert(e.next); assert(e.next.msg == name ~ ".2"); assert(!e.next.next); } } void main() { auto first = new Fiber(() => fiber("first")); auto second = new Fiber(() => fiber("second")); first.call(); second.call(); first.call(); second.call(); first.call(); second.call(); } --- Because the current implementation keeps information about the inflight exceptions in a TLS variable, switching contexts while an exception is in flight (i.e., from a finally block or dtor) completely breaks EH. More specifically, exceptions might disappear from one thread and might be appended to the exception chain of another thread. The solution is to save/restore the per-stack EH metadata on fiber context switches. I am not going to fix this for DMD's druntime, but will link the LDC patch for reference here once it's done.
Comment #1 by code — 2015-09-24T14:51:20Z
Comment #2 by github-bugzilla — 2015-09-25T00:37:01Z
Commits pushed to master at https://github.com/D-Programming-Language/druntime https://github.com/D-Programming-Language/druntime/commit/f6633abb43ea1f2464d3a772b8f8fe78216ffd8e Fix Issue 15104 - Fiber context switch in finally blocks breaks EH https://github.com/D-Programming-Language/druntime/commit/f0f8edaeb56294460aedbae3d91c7d3b304516b6 Merge pull request #1397 from klickverbot/fix-15104 Fix Issue 15104 - Fiber context switch in finally blocks breaks EH
Comment #3 by github-bugzilla — 2015-10-04T18:19:23Z