15
15
package connection
16
16
17
17
import (
18
- rawContext "context"
19
18
"sync"
20
19
"sync/atomic"
21
20
22
21
"github.com/lf-edge/ekuiper/contract/v2/api"
23
22
24
- "github.com/lf-edge/ekuiper/v2/internal/conf"
25
23
"github.com/lf-edge/ekuiper/v2/internal/topo/context"
26
24
"github.com/lf-edge/ekuiper/v2/pkg/modules"
27
25
)
@@ -32,10 +30,8 @@ type ConnWrapper struct {
32
30
conn modules.Connection
33
31
err error
34
32
l sync.RWMutex
35
- // context for connection wait only
36
- waitCtx rawContext.Context
37
- // context for the lifecycle
38
- stop rawContext.CancelFunc
33
+ readCh chan struct {}
34
+ detachCh chan struct {}
39
35
}
40
36
41
37
func (cw * ConnWrapper ) setConn (conn modules.Connection , err error ) {
@@ -50,7 +46,8 @@ func (cw *ConnWrapper) Wait(connectorCtx api.StreamContext) (modules.Connection,
50
46
select {
51
47
case <- connectorCtx .Done ():
52
48
connectorCtx .GetLogger ().Infof ("stop waiting connection" )
53
- case <- cw .waitCtx .Done ():
49
+ case <- cw .readCh :
50
+ case <- cw .detachCh :
54
51
}
55
52
cw .l .RLock ()
56
53
defer cw .l .RUnlock ()
@@ -63,20 +60,16 @@ func (cw *ConnWrapper) IsInitialized() bool {
63
60
return cw .initialized
64
61
}
65
62
66
- func newConnWrapper (callerCtx api.StreamContext , meta * Meta ) * ConnWrapper {
67
- callerCtx .GetLogger ().Infof ("creating new connection wrapper" )
68
- wctx , onConnect := rawContext .WithCancel (rawContext .Background ())
69
- contextLogger := conf .Log .WithField ("conn" , meta .ID )
70
- connCtx , stop := context .WithValue (context .Background (), context .LoggerKey , contextLogger ).WithCancel ()
63
+ func newConnWrapper (ctx api.StreamContext , meta * Meta ) * ConnWrapper {
71
64
cw := & ConnWrapper {
72
- ID : meta .ID ,
73
- waitCtx : wctx ,
74
- stop : stop ,
65
+ ID : meta .ID ,
66
+ readCh : make ( chan struct {}) ,
67
+ detachCh : make ( chan struct {}) ,
75
68
}
76
69
go func () {
77
- conn , err := createConnection (connCtx , meta )
70
+ conn , err := createConnection (ctx , meta )
78
71
cw .setConn (conn , err )
79
- onConnect ( )
72
+ close ( cw . readCh )
80
73
}()
81
74
return cw
82
75
}
0 commit comments