Skip to content

Commit 77c48c1

Browse files
authored
fix: call handle message inside handlers in a gouroutine (#148)
<!--- Provide a general summary of your changes in the Title above --> Oops 😅 ## Description <!--- Describe your changes in detail --> ## Related Issue Or Context <!--- If suggesting a new feature or change, please discuss it in an issue first --> <!--- If fixing a bug, there should be an issue describing it with steps to reproduce --> <!--- Otherwise, describe context and motivation for change herre --> Closes: #<issue> ## How Has This Been Tested? Testing details. <!--- Please describe in detail how you tested your changes. --> <!--- Include details of your testing environment, and the tests you ran to --> <!--- see how your change affects other areas of the code, etc. --> ## Types of changes <!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: --> - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Documentation ## Checklist: <!--- Go over all the following points, and put an `x` in all the boxes that apply. --> <!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> - [ ] I have commented my code, particularly in hard-to-understand areas. - [ ] I have ensured that all acceptance criteria (or expected behavior) from issue are met - [ ] I have updated the documentation locally and in docs. - [ ] I have added tests to cover my changes. - [ ] I have ensured that all the checks are passing and green, I've signed the CLA bot
1 parent 006dde5 commit 77c48c1

File tree

6 files changed

+90
-78
lines changed

6 files changed

+90
-78
lines changed

chains/evm/message/across.go

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -184,19 +184,21 @@ func (h *AcrossMessageHandler) Listen(ctx context.Context) {
184184
select {
185185
case wMsg := <-msgChn:
186186
{
187-
d := &AcrossData{}
188-
err := json.Unmarshal(wMsg.Payload, d)
189-
if err != nil {
190-
log.Warn().Msgf("Failed unmarshaling across message: %s", err)
191-
continue
192-
}
193-
194-
d.ErrChn = make(chan error, 1)
195-
msg := NewAcrossMessage(d.Source, d.Destination, d)
196-
_, err = h.HandleMessage(msg)
197-
if err != nil {
198-
log.Err(err).Msgf("Failed handling across message %+v because of: %s", msg, err)
199-
}
187+
go func(wMsg *comm.WrappedMessage) {
188+
d := &AcrossData{}
189+
err := json.Unmarshal(wMsg.Payload, d)
190+
if err != nil {
191+
log.Warn().Msgf("Failed unmarshaling across message: %s", err)
192+
return
193+
}
194+
195+
d.ErrChn = make(chan error, 1)
196+
msg := NewAcrossMessage(d.Source, d.Destination, d)
197+
_, err = h.HandleMessage(msg)
198+
if err != nil {
199+
log.Err(err).Msgf("Failed handling across message %+v because of: %s", msg, err)
200+
}
201+
}(wMsg)
200202
}
201203
case <-ctx.Done():
202204
{

chains/evm/message/lifiEscrow.go

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -284,19 +284,21 @@ func (h *LifiEscrowMessageHandler) Listen(ctx context.Context) {
284284
select {
285285
case wMsg := <-msgChn:
286286
{
287-
d := &LifiEscrowData{}
288-
err := json.Unmarshal(wMsg.Payload, d)
289-
if err != nil {
290-
log.Warn().Msgf("Failed unmarshaling LiFi message: %s", err)
291-
continue
292-
}
293-
294-
d.ErrChn = make(chan error, 1)
295-
msg := NewLifiEscrowMessage(d.Source, d.Destination, d)
296-
_, err = h.HandleMessage(msg)
297-
if err != nil {
298-
log.Err(err).Msgf("Failed handling LiFi message %+v because of: %s", msg, err)
299-
}
287+
go func(wMsg *comm.WrappedMessage) {
288+
d := &LifiEscrowData{}
289+
err := json.Unmarshal(wMsg.Payload, d)
290+
if err != nil {
291+
log.Warn().Msgf("Failed unmarshaling LiFi message: %s", err)
292+
return
293+
}
294+
295+
d.ErrChn = make(chan error, 1)
296+
msg := NewLifiEscrowMessage(d.Source, d.Destination, d)
297+
_, err = h.HandleMessage(msg)
298+
if err != nil {
299+
log.Err(err).Msgf("Failed handling LiFi message %+v because of: %s", msg, err)
300+
}
301+
}(wMsg)
300302
}
301303
case <-ctx.Done():
302304
{

chains/evm/message/mayan.go

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -205,19 +205,21 @@ func (h *MayanMessageHandler) Listen(ctx context.Context) {
205205
select {
206206
case wMsg := <-msgChn:
207207
{
208-
d := &MayanData{}
209-
err := json.Unmarshal(wMsg.Payload, d)
210-
if err != nil {
211-
log.Warn().Msgf("Failed unmarshaling Mayan message: %s", err)
212-
continue
213-
}
214-
215-
d.ErrChn = make(chan error, 1)
216-
msg := NewMayanMessage(d.Source, d.Destination, d)
217-
_, err = h.HandleMessage(msg)
218-
if err != nil {
219-
log.Err(err).Msgf("Failed handling Mayan message %+v because of: %s", msg, err)
220-
}
208+
go func(wMsg *comm.WrappedMessage) {
209+
d := &MayanData{}
210+
err := json.Unmarshal(wMsg.Payload, d)
211+
if err != nil {
212+
log.Warn().Msgf("Failed unmarshaling Mayan message: %s", err)
213+
return
214+
}
215+
216+
d.ErrChn = make(chan error, 1)
217+
msg := NewMayanMessage(d.Source, d.Destination, d)
218+
_, err = h.HandleMessage(msg)
219+
if err != nil {
220+
log.Err(err).Msgf("Failed handling Mayan message %+v because of: %s", msg, err)
221+
}
222+
}(wMsg)
221223
}
222224
case <-ctx.Done():
223225
{

chains/evm/message/rhinestone.go

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -221,19 +221,21 @@ func (h *RhinestoneMessageHandler) Listen(ctx context.Context) {
221221
select {
222222
case wMsg := <-msgChn:
223223
{
224-
d := &RhinestoneData{}
225-
err := json.Unmarshal(wMsg.Payload, d)
226-
if err != nil {
227-
log.Warn().Msgf("Failed unmarshaling rhinestone message: %s", err)
228-
continue
229-
}
230-
231-
d.ErrChn = make(chan error, 1)
232-
msg := NewRhinestoneMessage(d.Source, d.Destination, d)
233-
_, err = h.HandleMessage(msg)
234-
if err != nil {
235-
log.Err(err).Msgf("Failed handling rhinestone message %+v because of: %s", msg, err)
236-
}
224+
go func(wMsg *comm.WrappedMessage) {
225+
d := &RhinestoneData{}
226+
err := json.Unmarshal(wMsg.Payload, d)
227+
if err != nil {
228+
log.Warn().Msgf("Failed unmarshaling rhinestone message: %s", err)
229+
return
230+
}
231+
232+
d.ErrChn = make(chan error, 1)
233+
msg := NewRhinestoneMessage(d.Source, d.Destination, d)
234+
_, err = h.HandleMessage(msg)
235+
if err != nil {
236+
log.Err(err).Msgf("Failed handling rhinestone message %+v because of: %s", msg, err)
237+
}
238+
}(wMsg)
237239
}
238240
case <-ctx.Done():
239241
{

chains/evm/message/sprinter.go

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -124,19 +124,21 @@ func (h *SprinterCreditMessageHandler) Listen(ctx context.Context) {
124124
select {
125125
case wMsg := <-msgChn:
126126
{
127-
d := &SprinterCreditData{}
128-
err := json.Unmarshal(wMsg.Payload, d)
129-
if err != nil {
130-
log.Warn().Msgf("Failed unmarshaling across message: %s", err)
131-
continue
132-
}
133-
134-
d.ErrChn = make(chan error, 1)
135-
msg := NewSprinterCreditMessage(d.Source, d.Destination, d)
136-
_, err = h.HandleMessage(msg)
137-
if err != nil {
138-
log.Err(err).Msgf("Failed handling across message %+v because of: %s", msg, err)
139-
}
127+
go func(wMsg *comm.WrappedMessage) {
128+
d := &SprinterCreditData{}
129+
err := json.Unmarshal(wMsg.Payload, d)
130+
if err != nil {
131+
log.Warn().Msgf("Failed unmarshaling across message: %s", err)
132+
return
133+
}
134+
135+
d.ErrChn = make(chan error, 1)
136+
msg := NewSprinterCreditMessage(d.Source, d.Destination, d)
137+
_, err = h.HandleMessage(msg)
138+
if err != nil {
139+
log.Err(err).Msgf("Failed handling across message %+v because of: %s", msg, err)
140+
}
141+
}(wMsg)
140142
}
141143
case <-ctx.Done():
142144
{

chains/evm/message/unlock.go

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -94,19 +94,21 @@ func (h *LifiUnlockHandler) Listen(ctx context.Context) {
9494
select {
9595
case wMsg := <-msgChn:
9696
{
97-
d := &LifiUnlockData{}
98-
err := json.Unmarshal(wMsg.Payload, d)
99-
if err != nil {
100-
log.Warn().Msgf("Failed unmarshaling across message: %s", err)
101-
continue
102-
}
103-
d.SigChn = make(chan interface{}, 1)
104-
105-
msg := NewLifiUnlockMessage(d.Source, d.Destination, d)
106-
_, err = h.HandleMessage(msg)
107-
if err != nil {
108-
log.Err(err).Msgf("Failed handling across message %+v because of: %s", msg, err)
109-
}
97+
go func(wMsg *comm.WrappedMessage) {
98+
d := &LifiUnlockData{}
99+
err := json.Unmarshal(wMsg.Payload, d)
100+
if err != nil {
101+
log.Warn().Msgf("Failed unmarshaling across message: %s", err)
102+
return
103+
}
104+
d.SigChn = make(chan interface{}, 1)
105+
106+
msg := NewLifiUnlockMessage(d.Source, d.Destination, d)
107+
_, err = h.HandleMessage(msg)
108+
if err != nil {
109+
log.Err(err).Msgf("Failed handling across message %+v because of: %s", msg, err)
110+
}
111+
}(wMsg)
110112
}
111113
case <-ctx.Done():
112114
{

0 commit comments

Comments
 (0)