-
Notifications
You must be signed in to change notification settings - Fork 26
Open
Description
While working on #81 I noticed some logging and investigated.
When a message exceeds the maximum allowed size (32KB), it is correctly rejected by MessageBatch, but two subsequent issues cause a noisy retry loop.
Issue 1: Empty batch is sent to API
In send_worker.rb, when all messages in a batch are rejected due to size limits, the worker still calls @transport.send with an empty batch:
# send_worker.rb:46
res = @transport.send @api_key, @batch # @batch may be empty hereThe log shows:
[posthog-ruby] a message exceeded the maximum allowed size
[posthog-ruby] Sending request for 0 items
Issue 2: JSON parsing fails on non-JSON response
When the server receives an invalid/empty request, it may return a non-JSON error response. The transport code assumes JSON:
# transport.rb:53
error = JSON.parse(body)['error']This throws a JSON::ParserError, which triggers the retry logic, resulting in:
[posthog-ruby] Retrying request, 10 retries left
[posthog-ruby] Retrying request, 9 retries left
...
[posthog-ruby] unexpected character: 'request' at line 1 column 1
Suggested fixes
- Skip sending if batch is empty in
send_worker.rb - Wrap JSON parsing in a rescue block in
transport.rb
Environment
- Ruby 3.4.5
- Rails 8.1.1
- posthog-ruby (local/dev version)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels