Skip to content

Commit 313f886

Browse files
committed
queue: queue.Take() returns an invalid task
The patch fixes the return an invalid task object from queue.Take(). It may happen if an encoded task data has a nil value [1]. After the fix queue.Take() returns a nil value in the case. 1. https://github.com/msgpack/msgpack/blob/master/spec.md#nil-format
1 parent 64e41c5 commit 313f886

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Versioning](http://semver.org/spec/v2.0.0.html) except to the first release.
3535
- Decimal package use a test function GetNumberLength instead of a
3636
package-level function getNumberLength (#219)
3737
- Datetime location after encode + decode is unequal (#217)
38+
- queue.Take() returns an invalid task (#222)
3839

3940
## [1.8.0] - 2022-08-17
4041

queue/queue.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,14 @@ func (qd *queueData) DecodeMsgpack(d *decoder) error {
467467
}
468468

469469
qd.task = &Task{data: qd.result, q: qd.q}
470-
d.Decode(&qd.task)
470+
if err = d.Decode(&qd.task); err != nil {
471+
return err
472+
}
473+
474+
if qd.task.Data() == nil {
475+
// It may happen if the decoder has a code.Nil value inside. As a
476+
// result, the task will not be decoded.
477+
qd.task = nil
478+
}
471479
return nil
472480
}

queue/task.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,9 @@ func (t *Task) DecodeMsgpack(d *decoder) error {
2929
return err
3030
}
3131
if t.data != nil {
32-
if err = d.Decode(t.data); err != nil {
33-
return fmt.Errorf("fffuuuu: %s", err)
34-
}
35-
} else {
36-
if t.data, err = d.DecodeInterface(); err != nil {
37-
return err
38-
}
32+
d.Decode(t.data)
33+
} else if t.data, err = d.DecodeInterface(); err != nil {
34+
return err
3935
}
4036
return nil
4137
}

0 commit comments

Comments
 (0)