Skip to content

Commit 7aac8c9

Browse files
committed
fix: prevent buffer reuse in async mode for Put method
If the mode is async, we need to copy request Blob to prevent fasthttp from reusing the buffer since we are going to use the buffer in a separate goroutine beyond the scope of the current request.
1 parent a434c18 commit 7aac8c9

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

stores/goredis/redis.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,12 @@ type putReq struct {
169169
// Put sets a value to given session but stored only on commit
170170
func (s *Store) Put(namespace, group, uri string, b fastcache.Item, ttl time.Duration) error {
171171
if s.config.Async {
172+
// If the mode is async, we need to copy b.Blob to prevent
173+
// fasthttp from reusing the buffer since we are going to
174+
// use the buffer in a separate goroutine beyond the scope
175+
// of the current request.
176+
b.Blob = append([]byte(nil), b.Blob...)
177+
172178
s.putBuf <- putReq{namespace, group, uri, b, ttl}
173179
return nil
174180
}

0 commit comments

Comments
 (0)