Skip to content

Fix current picture retry logic - #3253

Merged
MichaIng merged 1 commit into
motioneye-project:devfrom
Marijn0:fix-current-picture-retry-handling
Feb 1, 2026
Merged

MichaIng merged 1 commit into
motioneye-project:devfrom
Marijn0:fix-current-picture-retry-handling

Conversation

@Marijn0

@Marijn0 Marijn0 commented Jan 6, 2026 •

Copy link
Copy Markdown
Member

Fixes an issue where /picture/<id>/current did not return JPEG images when no frame was available yet.

The retry logic previously used IOLoop.add_timeout(), which scheduled a retry but immediately closed the HTTP request.
As a result, the client could receive a response with Content-Type: image/jpeg but an empty body.

The retry now runs within the same request using an awaited sleep, keeping the request open while waiting for the first JPEG frame from the internal MJPEG client, up to the intended retry limit.

This behavior matches the existing comment in the code, and I think it reflects the intended behavior?:

# picture is not available usually when the corresponding internal mjpeg client has been closed;
# get_current_picture() will make sure to start a client, but a jpeg frame is not available right away;
# wait at most 5 seconds and retry every 200 ms.

#2978

@MichaIng
MichaIng changed the base branch from main to dev January 9, 2026 12:00
@MichaIng MichaIng added this to the v0.43.2 milestone Jan 9, 2026
@MichaIng
MichaIng force-pushed the fix-current-picture-retry-handling branch from f97894b to db76c7b Compare January 9, 2026 12:02
@MichaIng

MichaIng commented Jan 9, 2026

Copy link
Copy Markdown
Member

This looks like an elegant solution, many thanks.

Do you have a set of settings or timing to replicate the issue with an empty response? Keeping the request open seems benefitial in any case, but replicating the exact issue with some added debug output might be a good learning, and probably the same affects other part of the code.

@Marijn0

Marijn0 commented Jan 9, 2026 •

Copy link
Copy Markdown
Member Author

Do you have a set of settings or timing to replicate the issue with an empty response?

Yes, of course, this can be replicated by:

  • Closing all connections to the motionEye server.

  • Waiting 10 seconds (or the number of seconds set in motioneye.conf here) for the mjpg client to close.

  • Request a snapshot using: curl -i http://127.0.0.1:8765/picture/1/current, and check the content-length.
    (this should now be 0)

  • Try again within 10 seconds and check the content-length again.
    (this returns a valid JPEG because the mjpg client was started by the first request).

Keeping the request open seems benefitial in any case, but replicating the exact issue with some added debug output might be a good learning, and probably the same affects other part of the code.

As far as I can see, this only affects /picture/<id>/current, since it relies on retrying while waiting for a frame to become available, and I did not find other handlers using this same retry pattern

Maybe we could add an HTTP error when no picture is available? For example:

raise HTTPError(503, f'Failed to get current picture for camera {camera_id}: no frame available',)

Replace IOLoop.add_timeout() with an awaited retry so the HTTP request
remains open until a frame is available or the retry limit is reached.
@MichaIng
MichaIng force-pushed the fix-current-picture-retry-handling branch from db76c7b to 5898c19 Compare February 1, 2026 20:22
@MichaIng MichaIng linked an issue Feb 1, 2026 that may be closed by this pull request

@MichaIng MichaIng left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works perfectly. A curl to the API in case also takes a little longer if no image is available yet (the retry loop), so one can "feel" in action what is going on 👍.

@MichaIng
MichaIng merged commit f37e4fa into motioneye-project:dev Feb 1, 2026
14 checks passed
@Marijn0
Marijn0 deleted the fix-current-picture-retry-handling branch February 2, 2026 07:54
@MichaIng MichaIng linked an issue Feb 2, 2026 that may be closed by this pull request
@MichaIng MichaIng linked an issue Feb 12, 2026 that may be closed by this pull request
@Marijn0 Marijn0 linked an issue Feb 14, 2026 that may be closed by this pull request
@Marijn0 Marijn0 mentioned this pull request Feb 14, 2026
@MichaIng MichaIng mentioned this pull request Mar 10, 2026
@MichaIng MichaIng mentioned this pull request Jun 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

wget of still images not working the first time snapshot url friert ein 0byte snapshot files - no new releases and bugfixes?

2 participants