Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit163e483

Browse files
committed
fix data race caused by webpush-go mutating msg []byte
1 parentd4ca160 commit163e483

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

‎coderd/notifications/push/push.go‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"errors"
88
"io"
99
"net/http"
10+
"slices"
1011
"sync"
1112

1213
"github.com/SherClockHolmes/webpush-go"
@@ -93,8 +94,8 @@ func (n *Notifier) Dispatch(ctx context.Context, userID uuid.UUID, notification
9394
subscription:=subscription
9495
eg.Go(func()error {
9596
n.log.Debug(ctx,"dispatching via push",slog.F("subscription",subscription.Endpoint))
96-
97-
resp,err:=webpush.SendNotificationWithContext(ctx,notificationJSON,&webpush.Subscription{
97+
cpy:=slices.Clone(notificationJSON)// Need to copy as webpush.SendNotificationWithContext modifies the slice.
98+
resp,err:=webpush.SendNotificationWithContext(ctx,cpy,&webpush.Subscription{
9899
Endpoint:subscription.Endpoint,
99100
Keys: webpush.Keys{
100101
Auth:subscription.EndpointAuthKey,

‎coderd/notifications/push/push_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ func TestPush(t *testing.T) {
179179
},
180180
}
181181

182-
err=manager.Dispatch(context.Background(),user.ID,notification)
182+
err=manager.Dispatch(ctx,user.ID,notification)
183183
require.NoError(t,err)
184184
assert.True(t,okEndpointCalled,"The valid endpoint should be called")
185185
assert.True(t,goneEndpointCalled,"The expired endpoint should be called")

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp