Skip to content

Commit

Permalink
fix: removing errLoadingWASM var and send it directly to the channel
Browse files Browse the repository at this point in the history
  • Loading branch information
WendelHime committed Nov 19, 2024
1 parent 810a92a commit 6aa256a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 14 deletions.
18 changes: 5 additions & 13 deletions chained/water_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ type waterImpl struct {
raddr string
reportDialCore reportDialCoreFn
dialer water.Dialer
errLoadingWASM error
readyMutex sync.Locker
readyChan chan error
}

Expand All @@ -42,23 +40,20 @@ func newWaterImpl(dir, addr string, pc *config.ProxyConfig, reportDialCore repor
raddr: addr,
reportDialCore: reportDialCore,
readyChan: make(chan error),
readyMutex: new(sync.Mutex),
}

b64WASM := ptSetting(pc, "water_wasm")
if b64WASM != "" {
go func() {
wasm, err := base64.StdEncoding.DecodeString(b64WASM)
if err != nil {
d.errLoadingWASM = log.Errorf("failed to decode water wasm: %w", err)
d.readyChan <- d.errLoadingWASM
d.readyChan <- log.Errorf("failed to decode water wasm: %w", err)
return
}

d.dialer, err = createDialer(ctx, wasm, transport)
if err != nil {
d.errLoadingWASM = log.Errorf("failed to create dialer: %w", err)
d.readyChan <- d.errLoadingWASM
d.readyChan <- log.Errorf("failed to create dialer: %w", err)
return
}
d.readyChan <- nil
Expand All @@ -72,24 +67,21 @@ func newWaterImpl(dir, addr string, pc *config.ProxyConfig, reportDialCore repor

r, err := d.loadWASM(ctx, transport, dir, wasmAvailableAt)
if err != nil {
d.errLoadingWASM = log.Errorf("failed to read wasm: %w", err)
d.readyChan <- d.errLoadingWASM
d.readyChan <- log.Errorf("failed to read wasm: %w", err)
return
}
defer r.Close()
b, err := io.ReadAll(r)
if err != nil {
d.errLoadingWASM = log.Errorf("failed to load wasm bytes: %w", err)
d.readyChan <- d.errLoadingWASM
d.readyChan <- log.Errorf("failed to load wasm bytes: %w", err)
return
}

log.Debugf("received wasm with %d bytes", len(b))

d.dialer, err = createDialer(ctx, b, transport)
if err != nil {
d.errLoadingWASM = log.Errorf("failed to create dialer: %w", err)
d.readyChan <- d.errLoadingWASM
d.readyChan <- log.Errorf("failed to create dialer: %w", err)
return
}
d.readyChan <- nil
Expand Down
1 change: 0 additions & 1 deletion chained/water_impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ func TestNewWaterImpl(t *testing.T) {
defer actual.close()
require.NoError(t, err)
require.NotNil(t, actual)
assert.NoError(t, actual.errLoadingWASM)
<-actual.readyChan
assert.NotNil(t, actual.dialer)
assert.NotNil(t, actual.reportDialCore)
Expand Down

0 comments on commit 6aa256a

Please sign in to comment.