@@ -8,13 +8,18 @@ import (
88 "strings"
99
1010 v1 "github.com/numaproj/numaflow-go/pkg/apis/proto/reduce/v1"
11+ "github.com/numaproj/numaflow-go/pkg/shared"
12+ epb "google.golang.org/genproto/googleapis/rpc/errdetails"
13+ "google.golang.org/grpc/codes"
14+ "google.golang.org/grpc/status"
1115)
1216
17+ var errReduceHandlerPanic = fmt .Errorf ("UDF_EXECUTION_ERROR(%s)" , shared .ContainerType )
18+
1319// reduceTask represents a task for a performing reduceStream operation.
1420type reduceTask struct {
1521 keys []string
1622 window * v1.Window
17- reducer Reducer
1823 inputCh chan Datum
1924 doneCh chan struct {}
2025}
@@ -57,6 +62,7 @@ type reduceTaskManager struct {
5762 tasks map [string ]* reduceTask
5863 responseCh chan * v1.ReduceResponse
5964 shutdownCh chan <- struct {}
65+ errorCh chan error
6066}
6167
6268func newReduceTaskManager (reducerCreatorHandle ReducerCreator , shutdownCh chan <- struct {}) * reduceTaskManager {
@@ -65,6 +71,7 @@ func newReduceTaskManager(reducerCreatorHandle ReducerCreator, shutdownCh chan<-
6571 tasks : make (map [string ]* reduceTask ),
6672 responseCh : make (chan * v1.ReduceResponse ),
6773 shutdownCh : shutdownCh ,
74+ errorCh : make (chan error , 1 ),
6875 }
6976}
7077
@@ -92,7 +99,10 @@ func (rtm *reduceTaskManager) CreateTask(ctx context.Context, request *v1.Reduce
9299 defer func () {
93100 if r := recover (); r != nil {
94101 log .Printf ("panic inside reduce handler: %v %v" , r , string (debug .Stack ()))
95- rtm .shutdownCh <- struct {}{}
102+ st , _ := status .Newf (codes .Internal , "%s: %v" , errReduceHandlerPanic , r ).WithDetails (& epb.DebugInfo {
103+ Detail : string (debug .Stack ()),
104+ })
105+ rtm .errorCh <- st .Err ()
96106 }
97107 }()
98108 // invoke the reduce function
@@ -135,6 +145,11 @@ func (rtm *reduceTaskManager) OutputChannel() <-chan *v1.ReduceResponse {
135145 return rtm .responseCh
136146}
137147
148+ // Method to get the error channel
149+ func (rtm * reduceTaskManager ) ErrorChannel () <- chan error {
150+ return rtm .errorCh
151+ }
152+
138153// WaitAll waits for all the reduce tasks to complete.
139154func (rtm * reduceTaskManager ) WaitAll () {
140155 var eofResponse * v1.ReduceResponse
0 commit comments