mirror of
https://github.com/criyle/go-judge.git
synced 2025-11-04 14:50:02 +08:00
stream: fix goroutine leak
This commit is contained in:
parent
aa41950f89
commit
581b925450
@ -79,15 +79,19 @@ func Start(baseCtx context.Context, s Stream, w worker.Worker, srcPrefix []strin
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("convert exec request: %w", err)
|
return fmt.Errorf("convert exec request: %w", err)
|
||||||
}
|
}
|
||||||
logger.Sugar().Debugf("request: %+v", rq)
|
closeFunc := func() {
|
||||||
defer func() {
|
|
||||||
for _, f := range streamIn {
|
for _, f := range streamIn {
|
||||||
f.Close()
|
f.Close()
|
||||||
}
|
}
|
||||||
|
streamIn = nil
|
||||||
for _, f := range streamOut {
|
for _, f := range streamOut {
|
||||||
f.Close()
|
f.Close()
|
||||||
}
|
}
|
||||||
}()
|
streamOut = nil
|
||||||
|
}
|
||||||
|
defer closeFunc()
|
||||||
|
|
||||||
|
logger.Sugar().Debugf("request: %+v", rq)
|
||||||
|
|
||||||
var wg errgroup.Group
|
var wg errgroup.Group
|
||||||
execCtx, execCancel := context.WithCancel(baseCtx)
|
execCtx, execCancel := context.WithCancel(baseCtx)
|
||||||
@ -120,6 +124,8 @@ func Start(baseCtx context.Context, s Stream, w worker.Worker, srcPrefix []strin
|
|||||||
err = sendLoop(ctx, s, outCh, rtCh, logger)
|
err = sendLoop(ctx, s, outCh, rtCh, logger)
|
||||||
|
|
||||||
cancel()
|
cancel()
|
||||||
|
closeFunc()
|
||||||
|
streamOut = nil
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@ -197,7 +197,10 @@ func (h *wsHandle) handleStream(c *gin.Context) {
|
|||||||
|
|
||||||
w := &streamWrapper{ctx: ctx, conn: conn, sendCh: make(chan stream.Response)}
|
w := &streamWrapper{ctx: ctx, conn: conn, sendCh: make(chan stream.Response)}
|
||||||
go w.sendLoop()
|
go w.sendLoop()
|
||||||
stream.Start(ctx, w, h.worker, h.srcPrefix, h.logger)
|
if err := stream.Start(ctx, w, h.worker, h.srcPrefix, h.logger); err != nil {
|
||||||
|
h.logger.Sugar().Debugln("stream start: ", err)
|
||||||
|
c.Error(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type contextMap struct {
|
type contextMap struct {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user