Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segmentation at sock.close() at loop.timer #205

Open
pavel-orekhov opened this issue Jan 23, 2018 · 3 comments
Open

Segmentation at sock.close() at loop.timer #205

pavel-orekhov opened this issue Jan 23, 2018 · 3 comments

Comments

@pavel-orekhov
Copy link

I tried to reopen socket at timer's handler. It runs in endless recursion at remove() because socketfd=0 after close() and commonfd=0 too.

`#include <iostream.>
#include <memory.>
#include <unistd.h>
#include "zmqpp.hpp"

int main(int argc, char* argv[]){
zmqpp::context zmqContext;
zmqpp::loop loop;
zmqpp::socket workerSock(zmqContext,zmqpp::socket_type::dealer);
workerSock.connect("tcp://localhost:5555");

loop.add(std::chrono::milliseconds(1000),0,[&](){
    loop.remove(workerSock);
    workerSock.close();
    //reopen sock in 5 sec
    return true;
 });

loop.start();
return 0;

}`

zmqpp::socket::socket(const zmqpp::context&, zmqpp::socket_type)0x55555577fd90

void zmqpp::loop::remove(const socket_t&)0x55555577fd90 1
void zmqpp::socket::close()0x55555577fd90
void zmqpp::loop::remove(const socket_t&)0 0

Thread 1 "closeAtTimer" received signal SIGSEGV, Segmentation fault.
0x000055555555d293 in zmqpp::poller::remove (this=0x7fffffffdd90, descriptor=0) at src/zmqpp/poller.cpp:108
108 remove(item);
(gdb) bt -10
#349301 0x000055555555d1d8 in zmqpp::poller::remove (this=, item=...) at src/zmqpp/poller.cpp:114
#349302 0x000055555555d298 in zmqpp::poller::remove (this=, descriptor=)
at src/zmqpp/poller.cpp:108
#349303 0x000055555555d1d8 in zmqpp::poller::remove (this=, item=...) at src/zmqpp/poller.cpp:114
#349304 0x000055555555d298 in zmqpp::poller::remove (this=, descriptor=)
at src/zmqpp/poller.cpp:108
#349305 0x000055555555d1d8 in zmqpp::poller::remove (this=this@entry=0x7fffffffdd90, item=...)
at src/zmqpp/poller.cpp:114
#349306 0x000055555555d247 in zmqpp::poller::remove (this=this@entry=0x7fffffffdd90, socket=...)
at src/zmqpp/poller.cpp:101
#349307 0x000055555555867d in zmqpp::loop::remove (this=0x7fffffffdd10, socket=...) at src/zmqpp/loop.cpp:124
#349308 0x0000555555558c6d in zmqpp::loop::flush_remove_later (this=this@entry=0x7fffffffdd10)
at src/zmqpp/loop.cpp:215
#349309 0x0000555555558e8f in zmqpp::loop::start (this=0x7fffffffdd10) at src/zmqpp/loop.cpp:151
#349310 0x00005555555567db in main (argc=, argv=) at closeAtTimer.cxx:20
(gdb)

@pavel-orekhov
Copy link
Author

segv205.patch.txt
fd==0 is valid fd.
The patch suggested. Please test it.

@pavel-orekhov
Copy link
Author

There are two problems after previous patch:

  • after socket::close called from loop.timer's handler loop::start breaks with exception "it is not socket"
  • after socket::close called from loop.timer's handler loop.remove cant remove socket from list

Both problems are because after socket::close() socket::_socket is null and it misscompares with list of sockets at loop and at poller level.

It is required to save socket::_socket at SOCKET::close() till LOOP::flush_remove_later().
Is it right to add field void* socket::_saved_socket for this problem?

@pavel-orekhov
Copy link
Author

the 205_2n3.patch.txt
suggested as a fix of mentioned problems.

pavel-orekhov pushed a commit to pavel-orekhov/zmqpp that referenced this issue Jan 29, 2018
pavel-orekhov pushed a commit to pavel-orekhov/zmqpp that referenced this issue Jan 29, 2018
  part 2: exception at loop.start()
  part 3: socket is not removed from items_
  via separate cb for close()
* testcases for it
pavel-orekhov pushed a commit to pavel-orekhov/zmqpp that referenced this issue Jan 29, 2018
pavel-orekhov pushed a commit to pavel-orekhov/zmqpp that referenced this issue Jan 29, 2018
  part 2: exception at loop.start()
  part 3: socket is not removed from items_
  via separate cb for close()
* testcases for it
pavel-orekhov pushed a commit to pavel-orekhov/zmqpp that referenced this issue Jan 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant