Skip to content

Commit 2f53c6e

Browse files
committed
ssl: Swallow errors during socket.close()
.. for reasons given in the comment
1 parent 2f04028 commit 2f53c6e

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

shared-module/ssl/SSLSocket.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,16 @@ static void ssl_socket_bind(ssl_sslsocket_obj_t *self, mp_obj_t addr_in) {
155155
}
156156

157157
static void ssl_socket_close(ssl_sslsocket_obj_t *self) {
158-
mp_call_method_n_kw(0, 0, self->close_args);
158+
// swallow any exception raised by the underlying close method.
159+
// This is not ideal. However, it avoids printing "MemoryError:"
160+
// when attempting to close a userspace socket object during gc_sweep_all
161+
nlr_buf_t nlr;
162+
if (nlr_push(&nlr) == 0) {
163+
mp_call_method_n_kw(0, 0, self->close_args);
164+
nlr_pop();
165+
} else {
166+
nlr_pop();
167+
}
159168
}
160169

161170
static void ssl_socket_setsockopt(ssl_sslsocket_obj_t *self, mp_obj_t level_obj, mp_obj_t opt_obj, mp_obj_t optval_obj) {

0 commit comments

Comments
 (0)