Small poll
Chris Pressey
cpressey@REDACTED
Wed Dec 17 21:28:33 CET 2003
On Wed, 17 Dec 2003 21:17:35 +0100
Pascal Brisset <pascal.brisset-ml@REDACTED> wrote:
> Chris Pressey writes:
> > foo(Bar) ->
> > ok = file:setcwd(moo(Bar)),
> > {ok, File} = file:open(zoo(Bar)),
> > {ok, Records} = read_records(File),
> > ok = file:close(File),
> > Records.
> >
> > So, the intent of the function is clearly to fail outright with
> > 'badmatch' if anything goes wrong. foo/1's callers presumably wrap
> > their calls to foo (or their calls to whatever eventually calls
> > foo) in a catch. [...]
>
> Note that if foo/1's caller catches failures from read_records/1,
> file descriptors will be leaked. Days later, the beam process runs
> out of descriptors and strange things happen. Been there.
>
> What would seasoned Erlangers recommend to avoid this ?
Well, I am not a seasoned Erlanger[1], but I imagine most of them would
recommend spawning foo/1 into it's own process, then monitoring it or
linking to it. Then, when the process running foo/1 dies, its
filehandles and other resources will be deallocated (IIRC.)
-Chris
[1] I just come with a little wasabi on the side.
More information about the erlang-questions
mailing list