@@ -174,8 +174,8 @@ public abstract class AbstractSendChannel<E> : SendChannel<E> {
174
174
result == = OFFER_SUCCESS -> true
175
175
// We should check for closed token on offer as well, otherwise offer won't be linearizable
176
176
// in the face of concurrent close()
177
- result == = OFFER_FAILED -> throw closedForSend?.sendException ? : return false
178
- result is Closed <* > -> throw result.sendException
177
+ result == = OFFER_FAILED -> throw closedForSend?.sendException?. also { recoverStackTrace(it) } ? : return false
178
+ result is Closed <* > -> throw recoverStackTrace( result.sendException)
179
179
else -> error(" offerInternal returned $result " )
180
180
}
181
181
}
@@ -192,7 +192,7 @@ public abstract class AbstractSendChannel<E> : SendChannel<E> {
192
192
}
193
193
is Closed <* > -> {
194
194
helpClose(enqueueResult)
195
- cont.resumeWithException (enqueueResult.sendException)
195
+ cont.resumeWithStackTrace (enqueueResult.sendException)
196
196
return @sc
197
197
}
198
198
}
@@ -206,7 +206,7 @@ public abstract class AbstractSendChannel<E> : SendChannel<E> {
206
206
offerResult == = OFFER_FAILED -> continue @loop
207
207
offerResult is Closed <* > -> {
208
208
helpClose(offerResult)
209
- cont.resumeWithException (offerResult.sendException)
209
+ cont.resumeWithStackTrace (offerResult.sendException)
210
210
return @sc
211
211
}
212
212
else -> error(" offerInternal returned $offerResult " )
@@ -405,7 +405,7 @@ public abstract class AbstractSendChannel<E> : SendChannel<E> {
405
405
when {
406
406
enqueueResult == = ALREADY_SELECTED -> return
407
407
enqueueResult == = ENQUEUE_FAILED -> {} // retry
408
- enqueueResult is Closed <* > -> throw enqueueResult.sendException
408
+ enqueueResult is Closed <* > -> throw recoverStackTrace( enqueueResult.sendException)
409
409
else -> error(" performAtomicIfNotSelected(TryEnqueueSendDesc) returned $enqueueResult " )
410
410
}
411
411
} else {
@@ -417,7 +417,7 @@ public abstract class AbstractSendChannel<E> : SendChannel<E> {
417
417
block.startCoroutineUnintercepted(receiver = this , completion = select.completion)
418
418
return
419
419
}
420
- offerResult is Closed <* > -> throw offerResult.sendException
420
+ offerResult is Closed <* > -> throw recoverStackTrace( offerResult.sendException)
421
421
else -> error(" offerSelectInternal returned $offerResult " )
422
422
}
423
423
}
@@ -571,7 +571,7 @@ public abstract class AbstractChannel<E> : AbstractSendChannel<E>(), Channel<E>
571
571
572
572
@Suppress(" UNCHECKED_CAST" )
573
573
private fun receiveResult (result : Any? ): E {
574
- if (result is Closed <* >) throw result.receiveException
574
+ if (result is Closed <* >) throw recoverStackTrace( result.receiveException)
575
575
return result as E
576
576
}
577
577
@@ -587,7 +587,7 @@ public abstract class AbstractChannel<E> : AbstractSendChannel<E>(), Channel<E>
587
587
// hm... something is not right. try to poll
588
588
val result = pollInternal()
589
589
if (result is Closed <* >) {
590
- cont.resumeWithException (result.receiveException)
590
+ cont.resumeWithStackTrace (result.receiveException)
591
591
return @sc
592
592
}
593
593
if (result != = POLL_FAILED ) {
@@ -617,7 +617,7 @@ public abstract class AbstractChannel<E> : AbstractSendChannel<E>(), Channel<E>
617
617
@Suppress(" UNCHECKED_CAST" )
618
618
private fun receiveOrNullResult (result : Any? ): E ? {
619
619
if (result is Closed <* >) {
620
- if (result.closeCause != null ) throw result.closeCause
620
+ if (result.closeCause != null ) throw recoverStackTrace( result.closeCause)
621
621
return null
622
622
}
623
623
return result as E
@@ -638,7 +638,7 @@ public abstract class AbstractChannel<E> : AbstractSendChannel<E>(), Channel<E>
638
638
if (result.closeCause == null )
639
639
cont.resume(null )
640
640
else
641
- cont.resumeWithException (result.closeCause)
641
+ cont.resumeWithStackTrace (result.closeCause)
642
642
return @sc
643
643
}
644
644
if (result != = POLL_FAILED ) {
@@ -751,7 +751,7 @@ public abstract class AbstractChannel<E> : AbstractSendChannel<E>(), Channel<E>
751
751
when {
752
752
pollResult == = ALREADY_SELECTED -> return
753
753
pollResult == = POLL_FAILED -> {} // retry
754
- pollResult is Closed <* > -> throw pollResult.receiveException
754
+ pollResult is Closed <* > -> throw recoverStackTrace( pollResult.receiveException)
755
755
else -> {
756
756
block.startCoroutineUnintercepted(pollResult as E , select.completion)
757
757
return
@@ -791,7 +791,7 @@ public abstract class AbstractChannel<E> : AbstractSendChannel<E>(), Channel<E>
791
791
block.startCoroutineUnintercepted(null , select.completion)
792
792
return
793
793
} else
794
- throw pollResult.closeCause
794
+ throw recoverStackTrace( pollResult.closeCause)
795
795
}
796
796
else -> {
797
797
// selected successfully
@@ -850,7 +850,7 @@ public abstract class AbstractChannel<E> : AbstractSendChannel<E>(), Channel<E>
850
850
851
851
private fun hasNextResult (result : Any? ): Boolean {
852
852
if (result is Closed <* >) {
853
- if (result.closeCause != null ) throw result.receiveException
853
+ if (result.closeCause != null ) recoverStackTrace( throw result.receiveException)
854
854
return false
855
855
}
856
856
return true
@@ -871,7 +871,7 @@ public abstract class AbstractChannel<E> : AbstractSendChannel<E>(), Channel<E>
871
871
if (result.closeCause == null )
872
872
cont.resume(false )
873
873
else
874
- cont.resumeWithException (result.receiveException)
874
+ cont.resumeWithStackTrace (result.receiveException)
875
875
return @sc
876
876
}
877
877
if (result != = POLL_FAILED ) {
@@ -884,7 +884,7 @@ public abstract class AbstractChannel<E> : AbstractSendChannel<E>(), Channel<E>
884
884
@Suppress(" UNCHECKED_CAST" )
885
885
override suspend fun next (): E {
886
886
val result = this .result
887
- if (result is Closed <* >) throw result.receiveException
887
+ if (result is Closed <* >) throw recoverStackTrace( result.receiveException)
888
888
if (result != = POLL_FAILED ) {
889
889
this .result = POLL_FAILED
890
890
return result as E
@@ -904,7 +904,7 @@ public abstract class AbstractChannel<E> : AbstractSendChannel<E>(), Channel<E>
904
904
if (closed.closeCause == null && nullOnClose)
905
905
cont.resume(null )
906
906
else
907
- cont.resumeWithException (closed.receiveException)
907
+ cont.resumeWithStackTrace (closed.receiveException)
908
908
}
909
909
override fun toString (): String = " ReceiveElement[$cont ,nullOnClose=$nullOnClose ]"
910
910
}
@@ -939,7 +939,7 @@ public abstract class AbstractChannel<E> : AbstractSendChannel<E>(), Channel<E>
939
939
val token = if (closed.closeCause == null )
940
940
cont.tryResume(false )
941
941
else
942
- cont.tryResumeWithException(closed.receiveException)
942
+ cont.tryResumeWithException(recoverStackTrace( closed.receiveException, cont) )
943
943
if (token != null ) {
944
944
iterator.result = closed
945
945
cont.completeResume(token)
@@ -1052,7 +1052,7 @@ public class SendElement(
1052
1052
) : LockFreeLinkedListNode(), Send {
1053
1053
override fun tryResumeSend (idempotent : Any? ): Any? = cont.tryResume(Unit , idempotent)
1054
1054
override fun completeResumeSend (token : Any ) = cont.completeResume(token)
1055
- override fun resumeSendClosed (closed : Closed <* >) = cont.resumeWithException (closed.sendException)
1055
+ override fun resumeSendClosed (closed : Closed <* >) = cont.resumeWithStackTrace (closed.sendException)
1056
1056
override fun toString (): String = " SendElement($pollResult )[$cont ]"
1057
1057
}
1058
1058
0 commit comments