continue
ev = fileevs[0][1]
- if ev & POLL_BAD:
- _check_fd_closed(fileno)
- # Unlikely: the exception should have been raised above
- raise e.OperationalError("connection socket closed")
ready = 0
if ev & select.POLLIN:
ready = READY_R
if ev & select.POLLOUT:
ready |= READY_W
+
+ if not ready and ev & POLL_BAD:
+ _check_fd_closed(fileno)
+ # Unlikely: the exception should have been raised above
+ raise e.OperationalError("connection socket closed")
+
s = gen.send(ready)
evmask = _poll_evmasks[s]
poll.modify(fileno, evmask)
rv = 0; /* success, maybe with timeout */
if (select_rv >= 0) {
- if (input_fd.revents & ~(POLLIN | POLLOUT)) {
+ if (input_fd.revents & POLLIN) { rv |= SELECT_EV_READ; }
+ if (input_fd.revents & POLLOUT) { rv |= SELECT_EV_WRITE; }
+ if (!rv && (input_fd.revents & ~(POLLIN | POLLOUT))) {
rv = CWAIT_SOCKET_ERROR;
}
- else {
- if (input_fd.revents & POLLIN) { rv |= SELECT_EV_READ; }
- if (input_fd.revents & POLLOUT) { rv |= SELECT_EV_WRITE; }
- }
}
#else
assert dt < 1.0
+@pytest.mark.parametrize("waitfn", waitfns)
+def test_wait_remote_closed(proxy, conn_cls, waitfn):
+ waitfn = getattr(waiting, waitfn)
+ proxy.start()
+ with conn_cls.connect(proxy.client_dsn, autocommit=True) as conn:
+ conn.pgconn.send_query(b"select 1")
+ proxy.stop()
+ with pytest.raises(psycopg.OperationalError):
+ gen = generators.execute(conn.pgconn)
+ waitfn(gen, conn.pgconn.socket, 0.1)
+
+
+def test_remote_closed(proxy, conn_cls, caplog):
+ caplog.clear()
+ proxy.start()
+ with conn_cls.connect(proxy.client_dsn) as conn:
+ proxy.stop()
+ with pytest.raises(psycopg.OperationalError):
+ conn.execute("select 1")
+
+ assert not caplog.messages
+
+
@pytest.mark.parametrize("waitfn", waitfns)
def test_wait_timeout_none_unsupported(waitfn):
waitfn = getattr(waiting, waitfn)
assert dt < 1.0
+@pytest.mark.parametrize("waitfn", waitfns)
+async def test_wait_remote_closed(proxy, aconn_cls, waitfn):
+ waitfn = getattr(waiting, waitfn)
+ proxy.start()
+ async with await aconn_cls.connect(proxy.client_dsn, autocommit=True) as conn:
+ conn.pgconn.send_query(b"select 1")
+ proxy.stop()
+ with pytest.raises(psycopg.OperationalError):
+ gen = generators.execute(conn.pgconn)
+ await waitfn(gen, conn.pgconn.socket, 0.1)
+
+
+async def test_remote_closed(proxy, aconn_cls, caplog):
+ caplog.clear()
+ proxy.start()
+ async with await aconn_cls.connect(proxy.client_dsn) as conn:
+ proxy.stop()
+ with pytest.raises(psycopg.OperationalError):
+ await conn.execute("select 1")
+
+ assert not caplog.messages
+
+
@pytest.mark.parametrize("waitfn", waitfns)
async def test_wait_timeout_none_unsupported(waitfn):
waitfn = getattr(waiting, waitfn)