Skip to content

Commit 5c32e3f

Browse files
authored
Feature: When accepting a connection, if the created file descriptor (FD) is 0, 1, or 2, avoid core dump (#129)
1 parent 5100aa1 commit 5c32e3f

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

trpc/runtime/iomodel/reactor/default/tcp_acceptor.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ int TcpAcceptor::HandleReadEvent() {
108108
NetworkAddress peer_addr;
109109
int conn_fd = socket_.Accept(&peer_addr);
110110
if (conn_fd >= 0) {
111+
// When Accept returns standard input(0),standard output(1),and standard error(2), just only log
112+
if (conn_fd < 3) {
113+
TRPC_LOG_WARN("Accept return std fd,conn_fd:" << conn_fd);
114+
}
111115
AcceptConnectionFunction& accept_handler = GetAcceptHandleFunction();
112116
if (accept_handler) {
113117
AcceptConnectionInfo info;

trpc/runtime/iomodel/reactor/fiber/fiber_acceptor.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ FiberConnection::EventAction FiberAcceptor::OnTcpReadable() {
118118
NetworkAddress peer_addr;
119119
int conn_fd = socket_.Accept(&peer_addr);
120120
if (conn_fd >= 0) {
121+
// When Accept returns standard input(0),standard output(1),and standard error(2), just only log
122+
if (conn_fd < 3) {
123+
TRPC_LOG_WARN("Accept return std fd,conn_fd:" << conn_fd);
124+
}
121125
if (accept_handler_) {
122126
AcceptConnectionInfo info;
123127

trpc/runtime/iomodel/reactor/fiber/fiber_reactor.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,9 @@ void TerminateAllReactor() {
226226
}
227227

228228
Reactor* GetReactor(std::size_t scheduling_group, int fd) {
229-
TRPC_CHECK(fd != 0 && fd != -1,
230-
"You're likely passing in a fd got from calling `Get()` on an "
231-
"invalid `Handle`.");
229+
TRPC_CHECK(fd != -1,
230+
"You're likely passing in a fd got from calling `Get()` on an "
231+
"invalid `Handle`.");
232232
if (fd == -2) {
233233
fd = Random<int>();
234234
}

0 commit comments

Comments
 (0)