bug risk: ctx
for DialContext
was reused everywhere
#75
Labels
Milestone
ctx
for DialContext
was reused everywhere
#75
Problem
If the
ctx
used inDialContext
is cancelled AFTER the function returns, the returnedwater.Conn
will be closed.See https://github.com/hwh33/water-context-bug for an example.
Cause
Two causes contributed to this bug risk.
WATER reuse the
ctx
fromDialContext
in all calls to WebAssembly-exported functionsConfigured the
water.Core
with thectx
passed toDialContext
:water/transport/v1/dialer.go
Lines 60 to 83 in d4faf1b
Then reused this
ctx
when invoking every single WebAssembly-exported functionwater/transport/v1/transport_module.go
Line 402 in d4faf1b
_init
:water/transport/v1/transport_module.go
Line 422 in d4faf1b
_dial_fixed
(to be merged with_dial
):water/transport/v1/transport_module.go
Line 454 in d4faf1b
_dial
:water/transport/v1/transport_module.go
Line 486 in d4faf1b
_accept
(not withDialContext
, but would suffer similar bug risks):water/transport/v1/transport_module.go
Line 518 in d4faf1b
_associate
(not withDialContext
, but would suffer similar bug risks):water/transport/v1/transport_module.go
Line 548 in d4faf1b
_ctrlpipe
:water/transport/v1/transport_module.go
Line 604 in d4faf1b
_start
:water/transport/v1/transport_module.go
Line 612 in d4faf1b
At least some function calls, IF NOT ALL, should not be dependent on the context passed in byDialContext
.Functions which MUST return before
DialContext
can return (_init
,_dial
,_ctrlpipe
) should depend on thectx
passed toDialContext
for no issue. However, the blocking main loop,_start
, should depend on a different context, probablycontext.Background()
.WATER explicitly configured
wazero
to terminate the execution whenctx
is canceled or timed out(wazero.RuntimeConfig).WithCloseOnContextDone(true)
is invoked by default:water/wazero_config.go
Lines 153 to 159 in d4faf1b
And wazero/config.go#L151-L172 noted that:
The text was updated successfully, but these errors were encountered: