Skip to content

blocking call in Http1xServerResponse.doSendFile() #5568

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
lllxin037 opened this issue May 12, 2025 · 2 comments
Open

blocking call in Http1xServerResponse.doSendFile() #5568

lllxin037 opened this issue May 12, 2025 · 2 comments
Labels
Milestone

Comments

@lllxin037
Copy link

lllxin037 commented May 12, 2025

Questions

file blocking call in async sendFile(). Can sendFile() be executed in worker thread executeBlocking()? I searched and found the answer is no.

Version

4.4.9

Context

Http1xServerResponse.sendFile() should be an async call and executed in event loop thread. However, I observed it calls raf = new RandomAccessFile(file, "r"); inside doSendFile():

raf = new RandomAccessFile(file, "r");

new RandomAccessFile() internally calls RandomAccessFile.open() which is a blocking IO operation.

Why sendFile() behave in such way ? In a high pressure workload, I saw thread has been blocked due to this.

Should I call sendFile() in executeBlocking() or not ? If not, what I can do ?

Do you have a reproducer?

No

Extra

Linux + JDK 17.

@lllxin037 lllxin037 added the bug label May 12, 2025
@vietj
Copy link
Member

vietj commented May 14, 2025

we will support in 5.0.1 a sendFile version that accepts a FileChannel leaving you the ability to avoid this and handle yourself the creation of the FileChannel

@vietj vietj added this to the 5.0.1 milestone May 14, 2025
@olivierayache
Copy link

Hello @lllxin037, I am currently working on a PR that might fix that (#5558)

This PR is in progress but the idea is to give the possibility to have a new version of sendFile that accept a FileChannel for HttpServerResponse

This will let you manage the FileChannel on your own and pass it to HttpServerResponse. The ownership of FileChannel closing will be on the caller side

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants