求救:Linux连接总是报:connection reset by peer问题!!!

hzgchina2208 2004-11-05 09:30:56
各位大哥:小弟我在Linux下写的服务程序,当压力很大(连接客户量多频繁、发送请求频繁)的时候,服务总是会部分连接报connection reset by peer错误,结果我的服务把它关闭!
  查了部分资料,大部分是认为Linux有个tcp_wrap守护服务程序来管理tcp,默认值为一秒只能连一个上来。。。现在想知道的是,即然这个程序能控制连接,有没有办法修改这个参数呢?
  顺便再问一个问题:系统总是会报“断开的管道”错误??
  请各位帮帮忙,急啊!!!(在外网会有这个问题,内网没有出现)
...全文
14150 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
hzgchina2208 2004-11-06
  • 打赏
  • 举报
回复
listen的第二个参数,我已设成最大值SOMAXCONN,我修正内核该值为256.我的服务器是双CPU,2G内存的,应该足够大,可能是我的压力程序连接太快太多,请求发送频繁!!!
hzgchina2208 2004-11-06
  • 打赏
  • 举报
回复
哈哈。。太好了,谢谢各位大哥,小弟搞定了!!!
connection reset by peer确实如zzw_happy(蒹葭苍苍)所说,tcp有三次握手过程,在其中握手还未到三次时,有一个确认过程没有收到而又超时,就会出现connection reset by peer.

管道错误是信号未屏蔽导致!!!太谢谢!!下面是一信号屏蔽函数,小弟只收集了Linux/Aix9000上的,奉献给大家!!
void InstalSignal()
{
signal(SIGHUP ,SIG_IGN ); /* hangup, generated when terminal disconnects */
signal(SIGINT ,SIG_IGN ); /* interrupt, generated from terminal special char */
signal(SIGQUIT ,SIG_IGN ); /* (*) quit, generated from terminal special char */
signal(SIGILL ,SIG_IGN ); /* (*) illegal instruction (not reset when caught)*/
signal(SIGTRAP ,SIG_IGN ); /* (*) trace trap (not reset when caught) */
signal(SIGABRT ,SIG_IGN ); /* (*) abort process */
#ifdef D_AIX
signal(SIGEMT ,SIG_IGN ); /* EMT intruction */
#endif
signal(SIGFPE ,SIG_IGN ); /* (*) floating point exception */
signal(SIGKILL ,SIG_IGN ); /* kill (cannot be caught or ignored) */
signal(SIGBUS ,SIG_IGN ); /* (*) bus error (specification exception) */
signal(SIGSEGV ,SIG_IGN ); /* (*) segmentation violation */
signal(SIGSYS ,SIG_IGN ); /* (*) bad argument to system call */
signal(SIGPIPE ,SIG_IGN ); /* write on a pipe with no one to read it */
signal(SIGALRM ,SIG_IGN ); /* alarm clock timeout */
//signal(SIGTERM ,stopproc ); /* software termination signal */
signal(SIGURG ,SIG_IGN ); /* (+) urgent contition on I/O channel */
signal(SIGSTOP ,SIG_IGN ); /* (@) stop (cannot be caught or ignored) */
signal(SIGTSTP ,SIG_IGN ); /* (@) interactive stop */
signal(SIGCONT ,SIG_IGN ); /* (!) continue (cannot be caught or ignored) */
signal(SIGCHLD ,SIG_IGN); /* (+) sent to parent on child stop or exit */
signal(SIGTTIN ,SIG_IGN); /* (@) background read attempted from control terminal*/
signal(SIGTTOU ,SIG_IGN); /* (@) background write attempted to control terminal */
signal(SIGIO ,SIG_IGN); /* (+) I/O possible, or completed */
signal(SIGXCPU ,SIG_IGN); /* cpu time limit exceeded (see setrlimit()) */
signal(SIGXFSZ ,SIG_IGN); /* file size limit exceeded (see setrlimit()) */

#ifdef D_AIX
signal(SIGMSG ,SIG_IGN); /* input data is in the ring buffer */
#endif

signal(SIGWINCH,SIG_IGN); /* (+) window size changed */
signal(SIGPWR ,SIG_IGN); /* (+) power-fail restart */
//signal(SIGUSR1 ,stopproc); /* user defined signal 1 */
//signal(SIGUSR2 ,stopproc); /* user defined signal 2 */
signal(SIGPROF ,SIG_IGN); /* profiling time alarm (see setitimer) */

#ifdef D_AIX
signal(SIGDANGER,SIG_IGN); /* system crash imminent; free up some page space */
#endif

signal(SIGVTALRM,SIG_IGN); /* virtual time alarm (see setitimer) */

#ifdef D_AIX
signal(SIGMIGRATE,SIG_IGN); /* migrate process */
signal(SIGPRE ,SIG_IGN); /* programming exception */
signal(SIGVIRT ,SIG_IGN); /* AIX virtual time alarm */
signal(SIGALRM1,SIG_IGN); /* m:n condition variables - RESERVED - DON'T USE */
signal(SIGWAITING,SIG_IGN); /* m:n scheduling - RESERVED - DON'T USE */
signal(SIGCPUFAIL ,SIG_IGN); /* Predictive De-configuration of Processors - */
signal(SIGKAP,SIG_IGN); /* keep alive poll from native keyboard */
signal(SIGRETRACT,SIG_IGN); /* monitor mode should be relinguished */
signal(SIGSOUND ,SIG_IGN); /* sound control has completed */
signal(SIGSAK ,SIG_IGN); /* secure attention key */
#endif
}
cvsuser 2004-11-05
  • 打赏
  • 举报
回复
listen的第二参数你传的几?
铖邑 2004-11-05
  • 打赏
  • 举报
回复
断开的管道 是指向一个已经关闭的socket写数据时,报告的错误。可以将该信号屏蔽signal(SIGPIPE, SIG_IGN);

至于connection reset by peer
在下也感到莫名其妙,于是搬张凳子等待高手ing
jkjium 2004-11-05
  • 打赏
  • 举报
回复
对方没有close就cancel了socket pair,你就会收到一个sig_pipe信号然后strerror会显示“connection reset by peer”的错误。防止程序退出解决方法就是处理SIGPIPE信号
pacman2000 2004-11-05
  • 打赏
  • 举报
回复
因为排队的数量有限,所以压力很大的时候系统会自动把队列外的断开连接。
通过加大listen的backlog可以增加队列数。另外,就是想系统设计上的其他方法来减少accept的等待时间。
zzw_happy 2004-11-05
  • 打赏
  • 举报
回复
tcp的某一方发出了tcp_sync包,
另一方就connection reset了
一般是程序不正常退出导致

23,216

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧