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

Closing connection in new_connection_msg handler leads to segmentation fault #344

Closed
ufownl opened this issue Sep 8, 2015 · 3 comments
Closed
Assignees
Labels

Comments

@ufownl
Copy link
Contributor

ufownl commented Sep 8, 2015

The code below will cause this issue.

#include <caf/all.hpp>
#include <caf/io/all.hpp>
#include <iostream>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

using namespace caf;
using namespace caf::io;

behavior test(broker* self) {
    return {
        [=] (const new_connection_msg& msg) {
            aout(self) << "connection accepted" << std::endl;
            self->close(msg.handle);
        },
        [] (const connection_closed_msg&) {}
    };
}

int main() {
    spawn_io_server(test, 2015);
    for (;;) {
        int fd = socket(AF_INET, SOCK_STREAM, 0);
        sockaddr_in sin;
        sin.sin_family = AF_INET;
        sin.sin_addr.s_addr = inet_addr("127.0.0.1");
        sin.sin_port = htons(2015);
        connect(fd, reinterpret_cast<sockaddr*>(&sin), sizeof(sin));
    }
    await_all_actors_done();
    shutdown();
    return 0;
}

Possible output:

connection accepted
connection accepted
connection accepted
connection accepted
connection accepted
connection accepted
connection accepted
connection accepted
connection accepted
connection accepted
connection accepted
hello(635,0x100bc7000) malloc: *** error for object 0x7fe12a405d08: incorrect checksum for freed object - object was probably modified after being freed.
*** set a breakpoint in malloc_error_break to debug
hello(635,0x100c4a000) malloc: *** error for object 0x7fe12a405d20: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
Segmentation fault: 11
connection accepted
connection accepted
connection accepted
connection accepted
connection accepted
connection accepted
connection accepted
connection accepted
hello(645,0x106ab7000) malloc: *** error for object 0x7fb163d00548: incorrect checksum for freed object - object was probably modified after being freed.
*** set a breakpoint in malloc_error_break to debug
Abort trap: 6
connection accepted
connection accepted
connection accepted
connection accepted
connection accepted
connection accepted
connection accepted
Segmentation fault: 11
@Hamdor
Copy link
Collaborator

Hamdor commented Sep 8, 2015

I was not able to reproduce this on develop branch (debian 8, gcc 4.9.2)
What is your system/compiler and on which branch this happened?

@ufownl
Copy link
Contributor Author

ufownl commented Sep 8, 2015

I tried it on develop branch.
System: OS X 10.10.5
Compiler: Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn)

@Neverlord Neverlord added the bug label Sep 8, 2015
@Neverlord Neverlord self-assigned this Sep 8, 2015
@Neverlord
Copy link
Member

I'll fix this with #343

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants