Skip to content

Commit

Permalink
Send to exact match only when notify in poller (#537)
Browse files Browse the repository at this point in the history
  • Loading branch information
dfarr authored Jan 29, 2025
1 parent bbb848a commit 1735b6c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
3 changes: 3 additions & 0 deletions internal/aio/plugin.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package aio

import "github.com/resonatehq/resonate/pkg/message"

type Message struct {
Type message.Type
Data []byte
Body []byte
Done func(bool, error)
Expand Down
6 changes: 6 additions & 0 deletions internal/app/plugins/poll/poll.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/resonatehq/resonate/internal/kernel/t_aio"
"github.com/resonatehq/resonate/internal/metrics"
"github.com/resonatehq/resonate/internal/util"
"github.com/resonatehq/resonate/pkg/message"
)

type Config struct {
Expand Down Expand Up @@ -305,6 +306,11 @@ func (w *PollWorker) Process(mesg *aio.Message) {
return
}

if mesg.Type == message.Notify && conn.id != data.Id {
mesg.Done(false, fmt.Errorf("no connection found for group %s and id %s", data.Group, data.Id))
return
}

// send message to connection
select {
case conn.ch <- mesg.Body:
Expand Down
16 changes: 16 additions & 0 deletions internal/app/plugins/poll/poll_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/prometheus/client_golang/prometheus"
"github.com/resonatehq/resonate/internal/aio"
"github.com/resonatehq/resonate/internal/metrics"
"github.com/resonatehq/resonate/pkg/message"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -190,6 +191,21 @@ func TestPollPlugin(t *testing.T) {
{"foo", []string{"a", "b", "c"}, "data: ok3"},
},
},
{
name: "NotifyMustBeSameGroupAndId",
mc: 5,
connections: []*Conn{
{"foo", "a"},
},
messages: []*Mesg{
{true, &aio.Message{Type: message.Notify, Data: []byte(`{"group":"foo","id":"a"}`), Body: []byte("ok1")}},
{false, &aio.Message{Type: message.Notify, Data: []byte(`{"group":"foo","id":"b"}`), Body: []byte("ok2")}},
{false, &aio.Message{Type: message.Notify, Data: []byte(`{"group":"foo","id":"c"}`), Body: []byte("ok3")}},
},
expected: []*Resp{
{"foo", []string{"a"}, "data: ok1"},
},
},
} {
t.Run(tc.name, func(t *testing.T) {
config := &Config{
Expand Down
9 changes: 5 additions & 4 deletions internal/app/subsystems/aio/sender/sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,17 +248,17 @@ func (w *SenderWorker) Process(sqe *bus.SQE[t_aio.Submission, t_aio.Completion])
var body []byte
var err error

messgType := sqe.Submission.Sender.Task.Mesg.Type
mesgType := sqe.Submission.Sender.Task.Mesg.Type

if messgType == message.Notify {
if mesgType == message.Notify {
util.Assert(sqe.Submission.Sender.Promise != nil, "promise must not be nil for a notify message")
body, err = json.Marshal(map[string]interface{}{
"type": messgType,
"type": mesgType,
"promise": sqe.Submission.Sender.Promise,
})
} else {
body, err = json.Marshal(map[string]interface{}{
"type": messgType,
"type": mesgType,
"task": sqe.Submission.Sender.Task,
"href": map[string]string{
"claim": sqe.Submission.Sender.ClaimHref,
Expand All @@ -277,6 +277,7 @@ func (w *SenderWorker) Process(sqe *bus.SQE[t_aio.Submission, t_aio.Completion])
counter := w.metrics.AioInFlight.WithLabelValues(plugin.String())

ok := plugin.Enqueue(&aio.Message{
Type: mesgType,
Data: recv.Data,
Body: body,
Done: func(success bool, err error) {
Expand Down

0 comments on commit 1735b6c

Please sign in to comment.