Skip to content
This repository was archived by the owner on Apr 24, 2025. It is now read-only.

Commit 72ffe0f

Browse files
wimspaargarenWim Spaargaren
andauthored
fix: cleanup contextToRootID map on proxy done and map name correction (#92)
Co-authored-by: Wim Spaargaren <[email protected]>
1 parent ad4af97 commit 72ffe0f

File tree

5 files changed

+28
-25
lines changed

5 files changed

+28
-25
lines changed

proxywasm/abi_lifecycle.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ func proxyOnContextCreate(contextID uint32, rootContextID uint32) {
2929

3030
//export proxy_on_done
3131
func proxyOnDone(contextID uint32) bool {
32+
defer func() {
33+
delete(currentState.contextIDToRootID, contextID)
34+
}()
3235
if ctx, ok := currentState.streams[contextID]; ok {
3336
currentState.setActiveContextID(contextID)
3437
delete(currentState.streams, contextID)

proxywasm/abi_lifecycle_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ func Test_proxyOnContextCreate(t *testing.T) {
1414

1515
var cnt int
1616
currentState = &state{
17-
rootContexts: map[uint32]*rootContextState{},
18-
httpStreams: map[uint32]HttpContext{},
19-
streams: map[uint32]StreamContext{},
20-
contextIDToRooID: map[uint32]uint32{},
17+
rootContexts: map[uint32]*rootContextState{},
18+
httpStreams: map[uint32]HttpContext{},
19+
streams: map[uint32]StreamContext{},
20+
contextIDToRootID: map[uint32]uint32{},
2121
}
2222

2323
SetNewRootContext(func(contextID uint32) RootContext {

proxywasm/vmstate.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ type state struct {
3434
newHttpContext func(rootContextID, contextID uint32) HttpContext
3535
httpStreams map[uint32]HttpContext
3636

37-
contextIDToRooID map[uint32]uint32
38-
activeContextID uint32
37+
contextIDToRootID map[uint32]uint32
38+
activeContextID uint32
3939
}
4040

4141
var currentState = &state{
42-
rootContexts: make(map[uint32]*rootContextState),
43-
httpStreams: make(map[uint32]HttpContext),
44-
streams: make(map[uint32]StreamContext),
45-
contextIDToRooID: make(map[uint32]uint32),
42+
rootContexts: make(map[uint32]*rootContextState),
43+
httpStreams: make(map[uint32]HttpContext),
44+
streams: make(map[uint32]StreamContext),
45+
contextIDToRootID: make(map[uint32]uint32),
4646
}
4747

4848
func SetNewRootContext(f func(contextID uint32) RootContext) {
@@ -85,7 +85,7 @@ func (s *state) createStreamContext(contextID uint32, rootContextID uint32) {
8585
}
8686

8787
ctx := s.newStreamContext(rootContextID, contextID)
88-
s.contextIDToRooID[contextID] = rootContextID
88+
s.contextIDToRootID[contextID] = rootContextID
8989
s.streams[contextID] = ctx
9090
}
9191

@@ -99,12 +99,12 @@ func (s *state) createHttpContext(contextID uint32, rootContextID uint32) {
9999
}
100100

101101
ctx := s.newHttpContext(rootContextID, contextID)
102-
s.contextIDToRooID[contextID] = rootContextID
102+
s.contextIDToRootID[contextID] = rootContextID
103103
s.httpStreams[contextID] = ctx
104104
}
105105

106106
func (s *state) registerHttpCallOut(calloutID uint32, callback HttpCalloutCallBack) {
107-
r := s.rootContexts[s.contextIDToRooID[s.activeContextID]]
107+
r := s.rootContexts[s.contextIDToRootID[s.activeContextID]]
108108
r.httpCallbacks[calloutID] = &struct {
109109
callback HttpCalloutCallBack
110110
callerContextID uint32

proxywasm/vmstate_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ func TestState_createStreamContext(t *testing.T) {
8484
rid uint32 = 10
8585
)
8686
s := &state{
87-
rootContexts: map[uint32]*rootContextState{rid: nil},
88-
streams: map[uint32]StreamContext{},
89-
newStreamContext: func(rootContextID, contextID uint32) StreamContext { return &sc{} },
90-
contextIDToRooID: map[uint32]uint32{},
87+
rootContexts: map[uint32]*rootContextState{rid: nil},
88+
streams: map[uint32]StreamContext{},
89+
newStreamContext: func(rootContextID, contextID uint32) StreamContext { return &sc{} },
90+
contextIDToRootID: map[uint32]uint32{},
9191
}
9292

9393
s.createStreamContext(cid, rid)
@@ -105,10 +105,10 @@ func TestState_createHttpContext(t *testing.T) {
105105
rid uint32 = 10
106106
)
107107
s := &state{
108-
rootContexts: map[uint32]*rootContextState{rid: nil},
109-
httpStreams: map[uint32]HttpContext{},
110-
newHttpContext: func(rootContextID, contextID uint32) HttpContext { return &hc{} },
111-
contextIDToRooID: map[uint32]uint32{},
108+
rootContexts: map[uint32]*rootContextState{rid: nil},
109+
httpStreams: map[uint32]HttpContext{},
110+
newHttpContext: func(rootContextID, contextID uint32) HttpContext { return &hc{} },
111+
contextIDToRootID: map[uint32]uint32{},
112112
}
113113

114114
s.createHttpContext(cid, rid)

proxywasm/vmstate_test_export.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ package proxywasm
1919
func VMStateReset() {
2020
// (@mathetake) I assume that the currentState be protected by lock on hostMux
2121
currentState = &state{
22-
rootContexts: make(map[uint32]*rootContextState),
23-
httpStreams: make(map[uint32]HttpContext),
24-
streams: make(map[uint32]StreamContext),
25-
contextIDToRooID: make(map[uint32]uint32),
22+
rootContexts: make(map[uint32]*rootContextState),
23+
httpStreams: make(map[uint32]HttpContext),
24+
streams: make(map[uint32]StreamContext),
25+
contextIDToRootID: make(map[uint32]uint32),
2626
}
2727
}
2828

0 commit comments

Comments
 (0)