Skip to content

Conversation

@smuuf
Copy link
Owner

@smuuf smuuf commented Oct 21, 2025

Fix: Avoid empty string as body of task message when posting tasks

json_encode($body) could return empty string, so the task's JSON could contain "body": "", which is catastrophic - Celery can't decode that message and crashes - and the message is kept in the queue, causing crashes again and again.

This could happen, for example, if any of the task arguments was a string that contained badly formed Unicode characters.

Now we:

  • Replace (tell json_encode() to) badly formed Unicode with "\ufffd" (REPLACEMENT CHARACTER).
  • For other problems with json_encoding we're strict and we'll throw JsonException.

Feature: AsyncResult::get()'s interval argument can now be a list

E.g. for interval specified as [0.1, 0.6, 10] we'll first wait 0.1s, then 0.6s, then 10s repeatedly, until the task is ready (or we time out).

smuuf added 2 commits October 21, 2025 16:11
`json_encode($body)` could return empty string, so the task's JSON
could contain `"body": ""`, which is catastrophic - Celery can't decode
that message and crashes - and the message is kept in the queue, causing
crashes again and again.

This could happen, for example, if any of the task arguments was a string
that contained badly formed Unicode characters.

Now we:
- Replace (tell json_encode() to) badly formed Unicode with "\ufffd"
(REPLACEMENT CHARACTER).
- For other problems with json_encoding we're strict and we'll throw
  `JsonException`.
E.g. for interval specified as `[0.1, 0.6, 10]` we'll first wait 0.1s,
then 0.6s, then 10s repeatedly, until the task is ready (or we time out).
@smuuf smuuf force-pushed the fix_bad_json_encode_and_improve_intervals branch from a867974 to 9cbc9a0 Compare October 21, 2025 14:11
@smuuf smuuf merged commit 844815f into master Oct 21, 2025
40 checks passed
@smuuf smuuf deleted the fix_bad_json_encode_and_improve_intervals branch October 21, 2025 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants