Use io.Copy over ioutil.ReadFile #17

Merged
solderpunk merged 1 commits from makeworld/molly-brown:master into master 2020-12-10 07:12:29 +00:00
Contributor

ioutil.ReadFile is a bad choice for servers, because it means the file is read completely into memory, for each request. This is not only slower than copying the file, but can also cause out-of-memory panics when the server is serving files larger than its available RAM, or files that are smaller but to multiple clients at once.

This is why konpeito.media goes down sometimes, as cat explained to me on IRC. They also sent me this stack trace, which is what led me to the right lines of code.

This is a critical bug for any servers serving larger files. Please merge as early as you can. Maybe announce on the mailing list too? Thanks.

`ioutil.ReadFile` is a bad choice for servers, because it means the file is read completely into memory, for each request. This is not only slower than copying the file, but can also cause out-of-memory panics when the server is serving files larger than its available RAM, or files that are smaller but to multiple clients at once. This is why `konpeito.media` goes down sometimes, as cat explained to me on IRC. They also sent me [this](https://paste.tildeverse.org/?d6bc5ba5c1c0d1a4#8diRzuekfsjnxaRoM7PDWLbu76mAZTwUTLjyp2YAADUz) stack trace, which is what led me to the right lines of code. This is a critical bug for any servers serving larger files. Please merge as early as you can. Maybe announce on the mailing list too? Thanks.
makeworld added 1 commit 2020-12-09 23:04:20 +00:00
solderpunk merged commit 34e05cc0b5 into master 2020-12-10 07:12:29 +00:00
Owner

Thanks a lot for this fix! I've merged it just now, I'll tag a new release and make an announcement later tonight.

Thanks a lot for this fix! I've merged it just now, I'll tag a new release and make an announcement later tonight.
Sign in to join this conversation.
No reviewers
No Label
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: solderpunk/molly-brown#17
No description provided.