Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/blockchain/msg_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func (ms *MsgSender) send(ctx context.Context, payload []byte) error {
// three hanging liteservers could block a request for ~180s, causing the
// caller (or an upstream proxy) to time out and receive an empty response.
ctx2, cancel := context.WithTimeout(ctx, 10*time.Second)
_, err := c.SendMessage(ctx2, payload)
_, err = c.SendMessage(ctx2, payload)
cancel()
if err == nil {
liteserverMessageSendMc.WithLabelValues(fmt.Sprintf("%d", serverNumber), "success", fmt.Sprintf("%d", i)).Inc()
Expand Down
26 changes: 26 additions & 0 deletions pkg/blockchain/msg_sender_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package blockchain

import (
"context"
"testing"
"time"

"github.com/stretchr/testify/require"
"github.com/tonkeeper/tongo/config"
"github.com/tonkeeper/tongo/liteapi"
)

func TestMsgSender_dropExpiredBatches(t *testing.T) {
Expand Down Expand Up @@ -57,3 +60,26 @@ func TestMsgSender_dropExpiredBatches(t *testing.T) {
})
}
}

// TestMsgSender_send_AllAttemptsFail is a regression test: send() must
// return the underlying error when every liteserver attempt fails, not
// swallow it. It previously returned nil because `_, err := c.SendMessage(...)`
// inside the retry loop shadowed the function-scoped err instead of assigning it.
func TestMsgSender_send_AllAttemptsFail(t *testing.T) {
badServer := config.LiteServer{
Host: "127.0.0.1:1", // nothing listens here; connection must fail
Key: "wQEUBFTZKUpFvUVWkT8vTsxRUKWZFqXOMpXFBS2ykRE=",
}
client, err := liteapi.NewClient(
liteapi.WithAsyncConnectionsInit(),
liteapi.WithLiteServers([]config.LiteServer{badServer}),
)
require.NoError(t, err)

ms := &MsgSender{sendingClients: []*liteapi.Client{client}}
sendCtx, sendCancel := context.WithTimeout(context.Background(), 5*time.Second)
defer sendCancel()

err = ms.send(sendCtx, []byte("payload content is irrelevant to send()"))
require.Error(t, err, "send() must surface the failure, not swallow it")
}
Loading