<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Hi folks,<div class=""><br class=""></div><div class="">I just filed an issue <a href="https://github.com/haskell/network/issues/447" class="">https://github.com/haskell/network/issues/447</a> with the network package, I'd like to post here too in seeking your wisedom at the same time.</div><div class=""><br class=""></div><div class=""><p style="box-sizing: border-box; margin-bottom: 16px; color: rgb(36, 41, 46); font-family: -apple-system, system-ui, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji"; font-size: 14px; font-variant-ligatures: normal; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); margin-top: 0px !important;" class="">In top-level doc, the minimal example echo server uses <code style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace; font-size: 11.9px; padding: 0.2em 0.4em; margin: 0px; background-color: rgba(27, 31, 35, 0.05); border-radius: 3px;" class="">Control.Exception.bracket</code> like this:</p><div class="highlight highlight-source-haskell" style="box-sizing: border-box; margin-bottom: 16px; background-color: rgb(255, 255, 255); color: rgb(36, 41, 46); font-family: -apple-system, system-ui, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji"; font-size: 14px; font-variant-ligatures: normal; orphans: 2; widows: 2; overflow: visible !important;"><pre style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace; font-size: 11.9px; margin-top: 0px; margin-bottom: 0px; overflow-wrap: normal; padding: 16px; overflow: auto; line-height: 1.45; background-color: rgb(246, 248, 250); border-radius: 3px; word-break: normal;" class=""> <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 92, 197);">E.</span>bracket (open addr) close loop
<span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">where</span>
resolve <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">=</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">do</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">let</span> hints <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">=</span> defaultHints {
addrFlags <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">=</span> [<span class="pl-ent" style="box-sizing: border-box; color: rgb(34, 134, 58);">AI_PASSIVE</span>]
, addrSocketType <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">=</span> <span class="pl-ent" style="box-sizing: border-box; color: rgb(34, 134, 58);">Stream</span>
}
<span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 92, 197);">head</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);"><$></span> getAddrInfo (<span class="pl-ent" style="box-sizing: border-box; color: rgb(34, 134, 58);">Just</span> hints) mhost (<span class="pl-ent" style="box-sizing: border-box; color: rgb(34, 134, 58);">Just</span> port)
open addr <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">=</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">do</span>
sock <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);"><-</span> socket (addrFamily addr) (addrSocketType addr) (addrProtocol addr)
setSocketOption sock <span class="pl-ent" style="box-sizing: border-box; color: rgb(34, 134, 58);">ReuseAddr</span> <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 92, 197);">1</span>
withFdSocket sock setCloseOnExecIfNeeded
bind sock <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">$</span> addrAddress addr
listen sock <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 92, 197);">1024</span>
<span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 92, 197);">return</span> sock
loop sock <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">=</span> forever <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">$</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">do</span>
(conn, _peer) <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);"><-</span> accept sock
void <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">$</span> forkFinally (server conn) (<span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 92, 197);">const</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">$</span> gracefulClose conn <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 92, 197);">5000</span>)</pre></div><p style="box-sizing: border-box; margin-top: 0px; margin-bottom: 16px; color: rgb(36, 41, 46); font-family: -apple-system, system-ui, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji"; font-size: 14px; font-variant-ligatures: normal; orphans: 2; widows: 2; background-color: rgb(255, 255, 255);" class="">I happened to copy the configuration with another machine's IP address to run on my dev machine, then of course it failed binding to the IP, but in this case I suspect <code style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace; font-size: 11.9px; padding: 0.2em 0.4em; margin: 0px; background-color: rgba(27, 31, 35, 0.05); border-radius: 3px;" class="">sock</code> above is leaked without <code style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace; font-size: 11.9px; padding: 0.2em 0.4em; margin: 0px; background-color: rgba(27, 31, 35, 0.05); border-radius: 3px;" class="">close</code>, as <code style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace; font-size: 11.9px; padding: 0.2em 0.4em; margin: 0px; background-color: rgba(27, 31, 35, 0.05); border-radius: 3px;" class="">open</code> failed at all, so <code style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace; font-size: 11.9px; padding: 0.2em 0.4em; margin: 0px; background-color: rgba(27, 31, 35, 0.05); border-radius: 3px;" class="">sock</code> is not given to <code style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace; font-size: 11.9px; padding: 0.2em 0.4em; margin: 0px; background-color: rgba(27, 31, 35, 0.05); border-radius: 3px;" class="">bracket</code> for it to do the cleanup.</p><div style="box-sizing: border-box; margin-top: 0px; color: rgb(36, 41, 46); font-family: -apple-system, system-ui, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji"; font-size: 14px; font-variant-ligatures: normal; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); margin-bottom: 0px !important;" class="">Is my suspicion correct ? Or I missed something that the example actually won't leak on binding errors ?</div></div><div class=""><br class=""></div><div class="">Best regards,</div><div class="">Compl</div><div class=""><br class=""></div></body></html>