Skip to content

Concurrent goroutine and WithRetryKey() Usage Leads to Request Discrepancies #435

@YukiTsuchida

Description

@YukiTsuchida

System Informations

  • Go version: 1.22
  • OS: All

Expected Behavior

When making multiple PushMessage API requests concurrently using goroutines, each request's X-Line-Retry-Key and message body should match and be sent as expected.

Current Behavior

Using goroutines to invoke the PushMessage API multiple times results in occasional mismatches between the X-Line-Retry-Key and the message content in the request body. This leads to the LINE API mistakenly identifying these requests as duplicates, returning a 409 error, and consequently failing to send some messages.

Steps to Reproduce

https://go.dev/play/p/6idORXgHYJ_s

Logs

Here is an example of the actual request logs, where the mismatch between the X-Line-Retry-Key and the text field in the request body can be confirmed:

POST /v2/bot/message/push HTTP/1.1
Host: 127.0.0.1:36111
Accept-Encoding: gzip
Authorization: Bearer channelToken
Content-Length: 52
Content-Type: application/json; charset=UTF-8
User-Agent: LINE-BotSDK-Go/8.4.0
X-Line-Retry-Key: 1

{"to":"to","messages":[{"type":"text","text":"1"}]}

POST /v2/bot/message/push HTTP/1.1
Host: 127.0.0.1:36111
Accept-Encoding: gzip
Authorization: Bearer channelToken
Content-Length: 52
Content-Type: application/json; charset=UTF-8
User-Agent: LINE-BotSDK-Go/8.4.0
X-Line-Retry-Key: 4

{"to":"to","messages":[{"type":"text","text":"4"}]}

POST /v2/bot/message/push HTTP/1.1
Host: 127.0.0.1:36111
Accept-Encoding: gzip
Authorization: Bearer channelToken
Content-Length: 52
Content-Type: application/json; charset=UTF-8
User-Agent: LINE-BotSDK-Go/8.4.0
X-Line-Retry-Key: 0

{"to":"to","messages":[{"type":"text","text":"0"}]}

POST /v2/bot/message/push HTTP/1.1
Host: 127.0.0.1:36111
Accept-Encoding: gzip
Authorization: Bearer channelToken
Content-Length: 52
Content-Type: application/json; charset=UTF-8
User-Agent: LINE-BotSDK-Go/8.4.0
X-Line-Retry-Key: 2

{"to":"to","messages":[{"type":"text","text":"2"}]}

POST /v2/bot/message/push HTTP/1.1
Host: 127.0.0.1:36111
Accept-Encoding: gzip
Authorization: Bearer channelToken
Content-Length: 52
Content-Type: application/json; charset=UTF-8
User-Agent: LINE-BotSDK-Go/8.4.0
X-Line-Retry-Key: 0                                              <-------- 0 (incorrect)

{"to":"to","messages":[{"type":"text","text":"3"}]}

Additional Context

Currently, I am working around this issue by creating a new instance of linebot.Client for each request, but this is merely a temporary workaround. This approach is not suitable, especially under circumstances of handling large-scale traffic. I am looking forward to a resolution for this problem.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions