diff --git a/extmod/modlwip.c b/extmod/modlwip.c
index afd60672927e23ea9b38da3727ce2856dad4ffb8..afe5ca9e7396fd56a7daf66ea0c832a76134ac6a 100644
--- a/extmod/modlwip.c
+++ b/extmod/modlwip.c
@@ -183,11 +183,11 @@ static const int error_lookup_table[] = {
 typedef struct _lwip_socket_obj_t {
     mp_obj_base_t base;
 
-    union {
+    volatile union {
         struct tcp_pcb *tcp;
         struct udp_pcb *udp;
     } pcb;
-    union {
+    volatile union {
         struct pbuf *pbuf;
         struct tcp_pcb *connection;
     } incoming;