posixbase._UnixWaker.connectionLost catches wrong exception.

[email protected]
Newsgroups gmane.comp.python.twisted.bugs
Message-ID <[email protected]>
New submission from jerub <[email protected]>:

This code from twisted.internet.posixbase._UnixWaker.conncetionLost:
{{{
    def connectionLost(self, reason):
        """Close both ends of my pipe.
        """
        if not hasattr(self, "o"):
            return
        for fd in self.i, self.o:
            try:
                os.close(fd)
            except IOError:
                pass
        del self.i, self.o
}}}

This closes both ends of the pipe by using {{{os.close()}}} and supresses errors by catching and throwing away {{{IOError}}}.

But running through the python source (2.6.1) shows me from {{{posixmodule.c}}}
{{{
static PyObject *
posix_close(PyObject *self, PyObject *args)
{
	int fd, res;
	if (!PyArg_ParseTuple(args, "i:close", &fd))
		return NULL;
	Py_BEGIN_ALLOW_THREADS
	res = close(fd);
	Py_END_ALLOW_THREADS
	if (res < 0)
		return posix_error();
	Py_INCREF(Py_None);
	return Py_None;
}
}}}

Two exceptions can be thrown, one from arg parsing (not an issue here) and one managed by {{{posix_error()}}}.

Posix error is:
{{{
static PyObject *
posix_error(void)
{
	return PyErr_SetFromErrno(PyExc_OSError);
}
}}}

Which can only be an OSError.

This has caused a traceback for me in a production piece of software.

----------
Type     : enhancement
Component: core
Keywords : 
Priority : normal
Nosy     : 
----------
http://twistedmatrix.com/trac/ticket/3880
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.