fix file descriptor leak in example http server code#4
fix file descriptor leak in example http server code#4adamyi wants to merge 2 commits intoajyoon:masterfrom
Conversation
|
Hey @ajyoon, just a friendly ping on this :) |
ajyoon
left a comment
There was a problem hiding this comment.
apologies for my delay in patching in this very important production server fix. It seems correct enough to me, but I have a commentary question
| Move to cell 51 | ||
| >>> | ||
|
|
||
| Close the opened file | ||
|
|
||
| The current cell is 49 | ||
| The source file descriptor is in cell 53 |
There was a problem hiding this comment.
The comment above says it moves to cell 51, but this comment here says it's 49?
|
@ajyoon @kailando I verified that the comment was wrong, but the code was correct. According to sendfile call: Memory layout is that: Our previous close call ended at cell 48. Indeed, moving it right by 3 would move to 51, and we're emptying out 51-54 so that 55 can be the first argument for close syscall. After close syscall, we shift left by 3, and would indeed return back to 48. |
Originally the code only closed the fd for the connection but not for the file.
I'm running this code in prod and it ran out of fds fairly quickly. This fix makes it more stable :)