From 4e513a855e38aeb0fc11a44e096f7553547836ad Mon Sep 17 00:00:00 2001 From: Willem Melching Date: Fri, 15 Nov 2019 15:42:55 -0800 Subject: [PATCH] msgq: dont clean up uninitialized sockerts --- messaging/impl_msgq.cc | 12 ++++++++---- messaging/impl_msgq.hpp | 4 ++-- messaging/stress.py | 19 +++++++++++++++++++ 3 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 messaging/stress.py diff --git a/messaging/impl_msgq.cc b/messaging/impl_msgq.cc index a930a80d5b5d0a..b45fc352d9f873 100644 --- a/messaging/impl_msgq.cc +++ b/messaging/impl_msgq.cc @@ -119,8 +119,10 @@ void MSGQSubSocket::setTimeout(int t){ } MSGQSubSocket::~MSGQSubSocket(){ - msgq_close_queue(q); - delete q; + if (q != NULL){ + msgq_close_queue(q); + delete q; + } } void MSGQPubSocket::connect(Context *context, std::string endpoint){ @@ -150,8 +152,10 @@ int MSGQPubSocket::send(char *data, size_t size){ } MSGQPubSocket::~MSGQPubSocket(){ - msgq_close_queue(q); - delete q; + if (q != NULL){ + msgq_close_queue(q); + delete q; + } } diff --git a/messaging/impl_msgq.hpp b/messaging/impl_msgq.hpp index 138bdfc89bf92d..3f7ec7a9bf6464 100644 --- a/messaging/impl_msgq.hpp +++ b/messaging/impl_msgq.hpp @@ -31,7 +31,7 @@ class MSGQMessage : public Message { class MSGQSubSocket : public SubSocket { private: - msgq_queue_t * q; + msgq_queue_t * q = NULL; int timeout; public: void connect(Context *context, std::string endpoint, std::string address, bool conflate=false); @@ -43,7 +43,7 @@ class MSGQSubSocket : public SubSocket { class MSGQPubSocket : public PubSocket { private: - msgq_queue_t * q; + msgq_queue_t * q = NULL; public: void connect(Context *context, std::string endpoint); int sendMessage(Message *message); diff --git a/messaging/stress.py b/messaging/stress.py new file mode 100644 index 00000000000000..88573723a0a826 --- /dev/null +++ b/messaging/stress.py @@ -0,0 +1,19 @@ +import time +from messaging_pyx import Context, Poller, SubSocket, PubSocket # pylint: disable=no-name-in-module, import-error + +#21845 +#32767 after closing mmap fd + +if __name__ == "__main__": + c = Context() + pub_sock = PubSocket() + pub_sock.connect(c, "controlsState") + + for i in range(int(1e10)): + print(i) + sub_sock = SubSocket() + sub_sock.connect(c, "controlsState") + + + pub_sock.send(b'a') + print(sub_sock.receive())