常见BUG Software caused connection abort: socket write error

本文深入探讨了ClientAbortException错误产生的原因及其解决方案。该异常通常发生在客户端中止与服务器的连接时,常见场景包括:服务器并发连接数超载、客户端意外关闭、浏览器停止请求等。文章还特别提到使用Servlet的OutputStream输出多个数据时,若客户端未完全接收所有数据,则可能引发此异常。

最近碰到一个莫名的BUG:

 

ClientAbortException:  java.net.SocketException: Software caused connection abort: socket write error

at org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:373)

at org.apache.tomcat.util.buf.ByteChunk.flushBuffer(ByteChunk.java:437)

at org.apache.tomcat.util.buf.ByteChunk.append(ByteChunk.java:351)

at org.apache.catalina.connector.OutputBuffer.writeBytes(OutputBuffer.java:396)

at org.apache.catalina.connector.OutputBuffer.write(OutputBuffer.java:385)

at org.apache.catalina.connector.CoyoteOutputStream.write(CoyoteOutputStream.java:93)

at java.io.ObjectOutputStream$BlockDataOutputStream.drain(ObjectOutputStream.java:1847)

at java.io.ObjectOutputStream$BlockDataOutputStream.writeByte(ObjectOutputStream.java:1885)

at java.io.ObjectOutputStream.writeFatalException(ObjectOutputStream.java:1546)

at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:333)

at com.cc.das.ufk.StaticInfoServlet.getReservoirStaticInfo(StaticInfoServlet.java:293)

at com.cc.das.ufk.StaticInfoServlet.processRequest(StaticInfoServlet.java:72)

at com.cc.das.ufk.StaticInfoServlet.doGet(StaticInfoServlet.java:889)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)

at com.cc.das.admin.DatabaseConFilter.doFilter(DatabaseConFilter.java:146)

 

程序运行正常,数据也没有出错,后台却老是报这个错误。在网上找了别人写的博客,这个问题的原因有几个: 

①:服务器的并发连接数超过了其承载量,服务器会将其中一些连接Down掉; 
②:客户关掉了浏览器,而服务器还在给客户端发送数据; 
③:浏览器端按了Stop 

④:用servlet的outputstream输出流下载图片时,当用户点击取消也会报这个错

 

花了些功夫最后找出来的原因是:用servlet的response.getOutputStream时,写回多个数据,而客户端没全部接收,可能会报下面这个错误。如: 

服务器上写了两条数据

out.writeObject("1");

out.writeObject("2");

 

客户端只接收一条

in.readObject(url);

 

这样的话也会报ClientAbortException这个错,以后注意。


还有一种情况,我页面加载时会去服务器下载图标或者图片,当我强制刷新页面是,不停刷新多次也会报此异常;

是因为write流没关闭,浏览器有主动停止进行下次刷新了;

2025-10-28T19:45:58.820318+08:00 0 [Note] - '::' resolves to '::'; 2025-10-28T19:45:58.821280+08:00 0 [Note] Server socket created on IP: '::'. 2025-10-28T19:45:58.846650+08:00 0 [Note] InnoDB: Buffer pool(s) load completed at 251028 19:45:58 2025-10-28T19:45:58.911119+08:00 0 [Note] Event Scheduler: Loaded 0 events 2025-10-28T19:45:58.912084+08:00 0 [Note] D:\newmysql\mysql-5.7.12-winx64\bin\mysqld: ready for connections. Version: '5.7.12-log' socket: '' port: 3306 MySQL Community Server (GPL) 2025-10-28T20:39:45.659482+08:00 15 [ERROR] InnoDB: Operating system error number 32 in a file operation. 2025-10-28T20:39:45.660451+08:00 15 [ERROR] InnoDB: The error means that another program is using InnoDB's files. This might be a backup or antivirus software or another instance of MySQL. Please close it to get rid of this error. 2025-10-28 20:39:55 0x740c InnoDB: Assertion failure in thread 29708 in file handler0alter.cc line 7404 InnoDB: Failing assertion: error == DB_SUCCESS InnoDB: We intentionally generate a memory trap. InnoDB: Submit a detailed bug report to http://bugs.mysql.com. InnoDB: If you get repeated assertion failures or crashes, even InnoDB: immediately after the mysqld startup, there may be InnoDB: corruption in the InnoDB tablespace. Please refer to InnoDB: http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html InnoDB: about forcing recovery. 2025-10-28T20:39:55.663376+08:00 0 [Note] InnoDB: page_cleaner: 1000ms intended loop took 9553ms. The settings might not be optimal. (flushed=0 and evicted=0, during the time.) 12:39:55 UTC - mysqld got exception 0x80000003 ; This could be because you hit a bug. It is also possible that this binary or one of the libraries it was linked against is corrupt, improperly built, or misconfigured. This error can also be caused by malfunctioning hardware. Attempting to collect some information that could help diagnose the problem. As this is a crash and something is definitely wrong, the information collection process might fail. key_buffer_size=536870912 read_buffer_size=131072 max_used_connections=51 max_threads=600 thread_count=50 connection_count=50 It is possible that mysqld could use up to key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 761977 K bytes of memory Hope that's ok; if not, decrease some variables in the equation. Thread pointer: 0x26ebec94ce0 Attempting backtrace. You can use the following information to find out where mysqld died. If you see no messages after this, something went terribly wrong... 7ff754c49812 mysqld.exe!my_sigabrt_handler()[my_thr_init.c:449] 7ff754fee349 mysqld.exe!raise()[winsig.c:587] 7ff754fed240 mysqld.exe!abort()[abort.c:82] 7ff754d49b08 mysqld.exe!ut_dbg_assertion_failed()[ut0dbg.cc:67] 7ff754e2f72f mysqld.exe!ha_innobase::commit_inplace_alter_table()[handler0alter.cc:8275] 7ff7545c1443 mysqld.exe!mysql_inplace_alter_table()[sql_table.cc:7449] 7ff7545bf17a mysqld.exe!mysql_alter_table()[sql_table.cc:9538] 7ff7546e565e mysqld.exe!Sql_cmd_alter_table::execute()[sql_alter.cc:316] 7ff754546aa5 mysqld.exe!mysql_execute_command()[sql_parse.cc:3521] 7ff75454938a mysqld.exe!mysql_parse()[sql_parse.cc:5525] 7ff75454239d mysqld.exe!dispatch_command()[sql_parse.cc:1432] 7ff7545433aa mysqld.exe!do_command()[sql_parse.cc:999] 7ff7545081e4 mysqld.exe!handle_connection()[connection_handler_per_thread.cc:301] 7ff754f2cd92 mysqld.exe!pfs_spawn_thread()[pfs.cc:2191] 7ff754c4967b mysqld.exe!win_thread_start()[my_thread.c:38] 7ff754feddbf mysqld.exe!_callthreadstartex()[threadex.c:376] 7ff754fee00a mysqld.exe!_threadstartex()[threadex.c:354] 7ffaba1f84d4 KERNEL32.DLL!BaseThreadInitThunk() 7ffabc6ee871 ntdll.dll!RtlUserThreadStart() Trying to get some variables. Some pointers may be invalid and cause the dump to abort. Query (26ebece8580): ALTER TABLE formmain_0495 DROP COLUMN field0028 Connection ID (thread ID): 15 Status: NOT_KILLED The manual page at http://dev.mysql.com/doc/mysql/en/crashing.html contains information that should help you find out what is causing the crash. 2025-10-28T20:43:23.759825+08:00 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2025-10-28T20:43:23.759825+08:00 0 [Warning] Insecure configuration for --secure-file-priv: Current value does not restrict location of generated files. Consider setting it to a valid, non-empty path. 2025-10-28T20:43:23.760771+08:00 0 [Note] D:\newmysql\mysql-5.7.12-winx64\bin\mysqld (mysqld 5.7.12-log) starting as process 39684 ... 2025-10-28T20:43:23.818393+08:00 0 [Note] InnoDB: Mutexes and rw_locks use Windows interlocked functions 2025-10-28T20:43:23.819370+08:00 0 [Note] InnoDB: Uses event mutexes 2025-10-28T20:43:23.819370+08:00 0 [Note] InnoDB: _mm_lfence() and _mm_sfence() are used for memory barrier 2025-10-28T20:43:23.820343+08:00 0 [Note] InnoDB: Compressed tables use zlib 1.2.3 2025-10-28T20:43:23.821322+08:00 0 [Note] InnoDB: Number of pools: 1 2025-10-28T20:43:23.822294+08:00 0 [Note] InnoDB: Not using CPU crc32 instructions 2025-10-28T20:43:23.866243+08:00 0 [Note] InnoDB: Initializing buffer pool, total size = 8G, instances = 8, chunk size = 128M 2025-10-28T20:43:24.265683+08:00 0 [Note] InnoDB: Completed initialization of buffer pool 2025-10-28T20:43:24.414092+08:00 0 [Note] InnoDB: Highest supported file format is Barracuda. 2025-10-28T20:43:24.508818+08:00 0 [Note] InnoDB: Log scan progressed past the checkpoint lsn 933908534 2025-10-28T20:43:24.633818+08:00 0 [Note] InnoDB: Doing recovery: scanned up to log sequence number 933994745 2025-10-28T20:43:24.639683+08:00 0 [Note] InnoDB: Ignoring data file '.\oa\formmain_0495.ibd' with space ID 1585. Another data file called .\oa\#sql-ib1600-4242521553.ibd exists with the same space ID. 2025-10-28T20:43:24.641629+08:00 0 [Note] InnoDB: Ignoring data file '.\oa\formmain_0495.ibd' with space ID 1583. Another data file called .\oa\#sql-ib1602-4242521554.ibd exists with the same space ID. 2025-10-28T20:43:24.643587+08:00 0 [Note] InnoDB: Ignoring data file '.\oa\formmain_0495.ibd' with space ID 1585. Another data file called .\oa\#sql-ib1600-4242521553.ibd exists with the same space ID. 2025-10-28T20:43:24.647490+08:00 0 [Note] InnoDB: Ignoring data file '.\oa\formmain_0495.ibd' with space ID 1583. Another data file called .\oa\#sql-ib1602-4242521554.ibd exists with the same space ID. 2025-10-28T20:43:24.661159+08:00 0 [Note] InnoDB: Database was not shutdown normally! 2025-10-28T20:43:24.661159+08:00 0 [Note] InnoDB: Starting crash recovery. 2025-10-28T20:43:24.844755+08:00 0 [Note] InnoDB: 1 transaction(s) which must be rolled back or cleaned up in total 47 row operations to undo 2025-10-28T20:43:24.845734+08:00 0 [Note] InnoDB: Trx id counter is 14848 2025-10-28T20:43:24.859405+08:00 0 [Note] InnoDB: Starting an apply batch of log records to the database... InnoDB: Progress in percent: 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 2025-10-28T20:43:25.704135+08:00 0 [Note] InnoDB: Apply batch completed 2025-10-28T20:43:32.680689+08:00 0 [Note] InnoDB: Starting in background the rollback of uncommitted transactions 2025-10-28T20:43:32.681665+08:00 0 [Note] InnoDB: Removed temporary tablespace data file: "ibtmp1" 2025-10-28T20:43:32.681665+08:00 0 [Note] InnoDB: Rolling back trx with id 14454, 47 rows to undo 2025-10-28T20:43:32.682647+08:00 0 [Note] InnoDB: Creating shared tablespace for temporary tables 2025-10-28T20:43:32.684595+08:00 0 [Note] InnoDB: Setting file '.\ibtmp1' size to 12 MB. Physically writing the file full; Please wait ... 2025-10-28T20:43:32.695334+08:00 0 [Note] InnoDB: Rollback of trx with id 14454 completed 2025-10-28T20:43:32.696312+08:00 0 [Note] InnoDB: Rollback of non-prepared transactions completed 2025-10-28T20:43:32.732452+08:00 0 [Note] InnoDB: File '.\ibtmp1' size is now 12 MB. 2025-10-28T20:43:32.757857+08:00 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active. 2025-10-28T20:43:32.758821+08:00 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active. 2025-10-28T20:43:32.760764+08:00 0 [Note] InnoDB: Waiting for purge to start 2025-10-28T20:43:32.812522+08:00 0 [Note] InnoDB: 5.7.12 started; log sequence number 933994745 2025-10-28T20:43:32.812522+08:00 0 [Note] InnoDB: page_cleaner: 1000ms intended loop took 8438ms. The settings might not be optimal. (flushed=0 and evicted=0, during the time.) 2025-10-28T20:43:32.813529+08:00 0 [Note] Plugin 'FEDERATED' is disabled. 2025-10-28T20:43:32.813529+08:00 0 [Note] InnoDB: Loading buffer pool(s) from D:\newmysql\mysql-5.7.12-winx64\data\ib_buffer_pool 2025-10-28T20:43:32.830109+08:00 0 [Warning] Failed to set up SSL because of the following SSL library error: SSL context is not usable without certificate and private key 2025-10-28T20:43:32.832067+08:00 0 [Note] Server hostname (bind-address): '*'; port: 3306 2025-10-28T20:43:32.834022+08:00 0 [Note] IPv6 is available. 2025-10-28T20:43:32.834022+08:00 0 [Note] - '::' resolves to '::'; 2025-10-28T20:43:32.835011+08:00 0 [Note] Server socket created on IP: '::'. 2025-10-28T20:43:32.854535+08:00 0 [Note] InnoDB: Buffer pool(s) load completed at 251028 20:43:32 2025-10-28T20:43:32.904319+08:00 0 [Note] Event Scheduler: Loaded 0 events 2025-10-28T20:43:32.905296+08:00 0 [Note] D:\newmysql\mysql-5.7.12-winx64\bin\mysqld: ready for connections. Version: '5.7.12-log' socket: '' port: 3306 MySQL Community Server (GPL) 数据库异常崩溃,这个怎么解决
最新发布
10-29
### 关于 'Software caused connection abort: socket write error' 的中文解释 'Software caused connection abort: socket write error' 的中文含义可以翻译为 **“软件导致连接中断:套接字写入错误”**。该异常通常表示在网络通信过程中,由于某种原因导致一方主动关闭了连接或者无法继续完成数据传输操作。 --- ### 原因分析 #### 1. 客户端或服务器端资源未正确释放 当服务器正在释放资源时,如果客户端仍然尝试通过已失效的连接发送请求,则可能导致此异常发生[^1]。同样地,当客户端试图释放其本地资源时,若此时服务器仍有待处理的数据包到达,也可能引发类似的错误。 #### 2. 长时间闲置后的连接超时断开 对于长时间保持开启状态的服务而言,如果没有足够的活动流量维持连接有效性,某些中间设备(如防火墙、负载均衡器)可能会自动切断空闲链接[^2]。一旦这些被终止的会话重新激活时便会产生 `SocketException` 错误消息提示 “software caused connection abort”。 #### 3. JDBC 数据库连接池管理不当 在基于JDBC的应用程序里头,假如数据库连接对象长期得不到合理维护——例如未能及时归还给连接池亦或是超过了最大存活时限而遭到驱逐销毁的话;那么当下次需要用到它们执行查询命令之际便会抛出此类异常情况[^3]。 以下是针对以上几种常见场景下可能采取的一些预防措施: - 对于第一种情形中的同步问题可以通过引入心跳机制来解决; - 解决第二种状况可通过设置合理的KeepAlive参数以及定期向远端发送ping帧等方式实现; - 至于第三类现象则需优化数据库连接池配置并确保每次事务完成后都能妥善回收所借用的Connection实例。 ```java // 示例代码展示如何安全关闭socket以避免潜在的风险 try (ServerSocket serverSocket = new ServerSocket(port); Socket clientSocket = serverSocket.accept(); PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true); BufferedReader in = new BufferedReader( new InputStreamReader(clientSocket.getInputStream()))) { String inputLine; while ((inputLine = in.readLine()) != null) { System.out.println("Received: " + inputLine); out.println(inputLine); // Echo back to the client. } } catch (IOException e) { e.printStackTrace(); // Handle exceptions properly here. } ``` 上述例子展示了利用Java NIO API创建一个简单的回声服务器,并采用Try-with-resources语句保证所有涉及I/O流的对象能够在方法结束前得到适当清理从而减少意外崩溃的可能性。 --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值