Skip to content

Commit 119debe

Browse files
committed
fix(pluginhost): honor accepted emit results
1 parent 3e7e081 commit 119debe

2 files changed

Lines changed: 21 additions & 6 deletions

File tree

internal/pluginhost/stream_bridge.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,7 @@ func (s *streamBridgeStream) emit(ctx context.Context, chunk pluginapi.ExecutorS
158158
return errStreamBridgeClosed
159159
case s.emits <- request:
160160
}
161-
select {
162-
case err := <-request.done:
163-
return err
164-
case <-ctx.Done():
165-
return ctx.Err()
166-
}
161+
return <-request.done
167162
}
168163

169164
func (s *streamBridgeStream) close(errorMessage string) {
@@ -205,6 +200,7 @@ func (b *streamBridge) open(ctx context.Context) (string, <-chan pluginapi.Execu
205200
stream.abortStream()
206201
}
207202
if ctx != nil && ctx.Done() != nil {
203+
// Abort streams canceled before ExecuteStream can install cleanupWhenStreamDone.
208204
go func() {
209205
<-ctx.Done()
210206
cleanup()

internal/pluginhost/stream_bridge_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,25 @@ func TestStreamBridgeCloseUnblocksPendingEmit(t *testing.T) {
7171
}
7272
}
7373

74+
func TestStreamBridgeEmitUsesAcceptedPumpResultAfterContextCancellation(t *testing.T) {
75+
for range 1000 {
76+
ctx, cancel := context.WithCancel(context.Background())
77+
stream := &streamBridgeStream{
78+
emits: make(chan streamBridgeEmit),
79+
closed: make(chan struct{}),
80+
}
81+
go func() {
82+
request := <-stream.emits
83+
cancel()
84+
request.done <- nil
85+
}()
86+
87+
if err := stream.emit(ctx, pluginapi.ExecutorStreamChunk{Payload: []byte("accepted")}); err != nil {
88+
t.Fatalf("accepted emit returned error: %v", err)
89+
}
90+
}
91+
}
92+
7493
func TestStreamBridgeAbortClosesSaturatedStreamWithoutConsumer(t *testing.T) {
7594
bridge := newStreamBridge()
7695
streamID, chunks, cleanup := bridge.open(context.Background())

0 commit comments

Comments
 (0)