Skip to content

Commit

Permalink
When uncaught exceptions occur in the networkd threads, handle them.
Browse files Browse the repository at this point in the history
  • Loading branch information
sgielen committed Jun 17, 2017
1 parent c794005 commit 6cd2f5c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
5 changes: 4 additions & 1 deletion userland/networkd/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ bool client::send_error(std::string error) {
}

void client::run() {
while(1) {
while(1) try {
char buf[200];
// TODO: set non-blocking flag once kernel supports it
// this way, we can read until EOF instead of only 200 bytes
Expand Down Expand Up @@ -472,5 +472,8 @@ void client::run() {
return;
}
}
} catch(std::exception &e) {
dprintf(logfd, "*** Uncaught exception in client interface with fd %d\n", fd);
dprintf(logfd, "*** Error: \"%s\"\n", e.what());
}
}
11 changes: 9 additions & 2 deletions userland/networkd/interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,15 @@ interface::~interface()
void interface::start()
{
assert(rawsock >= 0);
thr = std::thread([this](){
run();
auto that = shared_from_this();
thr = std::thread([that](){
try {
that->run();
} catch(std::exception &e) {
dprintf(0, "*** Uncaught exception in handling incoming data on %s interface %s\n",
that->hwtype.c_str(), that->name.c_str());
dprintf(0, "*** Error: \"%s\"\n", e.what());
}
});
}

Expand Down
14 changes: 13 additions & 1 deletion userland/networkd/ip_socket.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "ip_socket.hpp"
#include "util.hpp"
#include <thread>
#include <cassert>

Expand Down Expand Up @@ -34,7 +35,18 @@ void ip_socket::start()

void ip_socket::run()
{
handle_requests(reversefd, this);
try {
handle_requests(reversefd, this);
} catch(std::exception &e) {
dprintf(0, "*** handle_requests threw an exception in ip_socket\n");
dprintf(0, "*** error: \"%s\"\n", e.what());
dprintf(0, "*** proto: %d\n", proto);
std::string ipd = ipv4_ntop(local_ip);
dprintf(0, "*** local bind: %s:%d\n", ipd.c_str(), local_port);
ipd = ipv4_ntop(peer_ip);
dprintf(0, "*** remote bind: %s:%d\n", ipd.c_str(), peer_port);
dprintf(0, "*** pseudo: %llu / reverse: %d\n", pseudofd, reversefd);
}
}

void ip_socket::stat_fget(cosix::pseudofd_t, cloudabi_filestat_t *buf)
Expand Down

0 comments on commit 6cd2f5c

Please sign in to comment.