Skip to content

Commit

Permalink
fix potential endless loop during queue msg/hook pagination when envi…
Browse files Browse the repository at this point in the history
…ronment has TZ UTC, triggered by tests introduced in previous test

time.Now() returns a timestamp with timezone Local. if you marshal & unmarshal
it again, it'll get the Local timezone again. unless the local timezone is UTC.
then it will get the UTC timezone. the same time.Time but with explicit UTC
timezone vs explicit UTC-as-Local timezone are not the same when comparing with
==. so comparison should be done with time.Time.Equal, or comparison should be
done after having called .Local() on parsed timestamps (so the explicit UTC
timezone gets converted to the UTC-as-Local timezone). somewhat surprising that
time.Local isn't the same as time.UTC if TZ=/TZ=UTC. there are warnings
throughout the time package about handling of UTC.
  • Loading branch information
mjl- committed Apr 16, 2024
1 parent 09fcc49 commit daa8848
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion develop.txt
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ done
- Update features & roadmap in README.md
- Write release notes, copy from previous.
- Build and run tests with previous major Go release.
- Run tests, including with race detector.
- Run tests, including with race detector, also with TZ= for UTC-behaviour.
- Run integration and upgrade tests.
- Run fuzzing tests for a while.
- Deploy to test environment. Test the update instructions.
Expand Down
8 changes: 4 additions & 4 deletions queue/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,9 @@ func (s HookSort) apply(q *bstore.Query[Hook]) error {
q.FilterNotEqual("ID", s.LastID)
var fieldEqual func(h Hook) bool
if s.Field == "NextAttempt" {
fieldEqual = func(h Hook) bool { return h.NextAttempt == last }
fieldEqual = func(h Hook) bool { return h.NextAttempt.Equal(last) }
} else {
fieldEqual = func(h Hook) bool { return h.Submitted == last }
fieldEqual = func(h Hook) bool { return h.Submitted.Equal(last) }
}
if s.Asc {
q.FilterGreaterEqual(s.Field, last)
Expand Down Expand Up @@ -454,9 +454,9 @@ func (s HookRetiredSort) apply(q *bstore.Query[HookRetired]) error {
q.FilterNotEqual("ID", s.LastID)
var fieldEqual func(hr HookRetired) bool
if s.Field == "LastActivity" {
fieldEqual = func(hr HookRetired) bool { return hr.LastActivity == last }
fieldEqual = func(hr HookRetired) bool { return hr.LastActivity.Equal(last) }
} else {
fieldEqual = func(hr HookRetired) bool { return hr.Submitted == last }
fieldEqual = func(hr HookRetired) bool { return hr.Submitted.Equal(last) }
}
if s.Asc {
q.FilterGreaterEqual(s.Field, last)
Expand Down
1 change: 1 addition & 0 deletions queue/hook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ func TestHookIncoming(t *testing.T) {
dec := json.NewDecoder(strings.NewReader(h.Payload))
err = dec.Decode(&in)
tcheck(t, err, "decode incoming webhook")
in.Meta.Received = in.Meta.Received.Local() // For TZ UTC.

expIncoming := webhook.Incoming{
From: []webhook.NameAddress{{Address: "[email protected]"}},
Expand Down
8 changes: 4 additions & 4 deletions queue/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,9 +492,9 @@ func (s Sort) apply(q *bstore.Query[Msg]) error {
q.FilterNotEqual("ID", s.LastID)
var fieldEqual func(m Msg) bool
if s.Field == "NextAttempt" {
fieldEqual = func(m Msg) bool { return m.NextAttempt == last }
fieldEqual = func(m Msg) bool { return m.NextAttempt.Equal(last) }
} else {
fieldEqual = func(m Msg) bool { return m.Queued == last }
fieldEqual = func(m Msg) bool { return m.Queued.Equal(last) }
}
if s.Asc {
q.FilterGreaterEqual(s.Field, last)
Expand Down Expand Up @@ -1015,9 +1015,9 @@ func (s RetiredSort) apply(q *bstore.Query[MsgRetired]) error {
q.FilterNotEqual("ID", s.LastID)
var fieldEqual func(m MsgRetired) bool
if s.Field == "LastActivity" {
fieldEqual = func(m MsgRetired) bool { return m.LastActivity == last }
fieldEqual = func(m MsgRetired) bool { return m.LastActivity.Equal(last) }
} else {
fieldEqual = func(m MsgRetired) bool { return m.Queued == last }
fieldEqual = func(m MsgRetired) bool { return m.Queued.Equal(last) }
}
if s.Asc {
q.FilterGreaterEqual(s.Field, last)
Expand Down

0 comments on commit daa8848

Please sign in to comment.