| Description | I've seen an issue with my mantis install where I add note, and it can be slow (like 20-30 seconds) due to attachments. Often if we have a frontend bug/bugfix, we'll do a screenshot of the fix or the issue.
I do php development, but I fed this into cursor and received the below check and solution. It does the session write after the fact.
Summary
- Call
session_write_close() in file_download.php after auth, CSRF purge, and headers, but before streaming file content.
- Prevents same-user requests (e.g. Add Note) from blocking while attachment inline previews or downloads hold the PHP session lock.
Problem
PHP's default file session handler allows only one request per session at a time. file_download.php kept the session open for the entire transfer. On issue views with multiple inline image previews, those downloads serialized behind one lock, so submitting Add Note could feel intermittently slow even though the note insert itself was fast. Refreshing the issue page still felt fast because HTML returned immediately and previews loaded in the background.
Solution
Close the session after form_security_purge( 'file_show_inline' ) and response headers are sent, immediately before readfile() / echoing DB content. CSRF token cleanup still persists; only the transfer holds the request open.
Test plan
- [ ] Open an issue with several image attachments (inline previews enabled)
- [ ] Confirm previews still render
- [ ] While previews are loading, submit Add Note (text only) and confirm it no longer waits on downloads
- [ ] Download an attachment normally and confirm content/headers are unchanged
- [ ] Confirm repeated inline preview loads still validate/purge
file_show_inline tokens correctly
|
|---|
| Additional Information | Solution that seems to fix it:
Below added to file_download.php
header( 'X-Content-Type-Options: nosniff' );
# Release session after CSRF purge / headers, before streaming, so other
# same-user requests (e.g. Add Note) are not blocked by attachment downloads.
session_write_close();
# dump file content to the connection.
EDIT (dregad) added markdown code block |
|---|