mirror of
https://github.com/TheWhiteDog9487/WebAPI.git
synced 2026-08-11 23:01:30 +08:00
写入数据库时加入错误捕获以防未释放锁导致卡死整个系统
This commit is contained in:
@@ -56,16 +56,24 @@ public class LogClientInfo implements Filter {
|
|||||||
Instant.now(),
|
Instant.now(),
|
||||||
null,
|
null,
|
||||||
null );
|
null );
|
||||||
|
try {
|
||||||
SQLiteWriteLock.lock();
|
SQLiteWriteLock.lock();
|
||||||
Log = AccessLogRepository.save(Log);
|
Log = AccessLogRepository.save(Log); }
|
||||||
SQLiteWriteLock.unlock();
|
catch (Exception e) {
|
||||||
|
log.error(e.getLocalizedMessage()); }
|
||||||
|
finally {
|
||||||
|
SQLiteWriteLock.unlock(); }
|
||||||
chain.doFilter(request, Response);
|
chain.doFilter(request, Response);
|
||||||
var ResponseBody = IgnorePaths.stream()
|
var ResponseBody = IgnorePaths.stream()
|
||||||
.anyMatch( path -> HttpServletRequest.getRequestURI().startsWith(path) )
|
.anyMatch( path -> HttpServletRequest.getRequestURI().startsWith(path) )
|
||||||
? null : new String( Response.getContentAsByteArray(), Response.getCharacterEncoding() );
|
? null : new String( Response.getContentAsByteArray(), Response.getCharacterEncoding() );
|
||||||
Log.setResponseStatusCode(HttpServletResponse.getStatus());
|
Log.setResponseStatusCode(HttpServletResponse.getStatus());
|
||||||
Log.setResponseBody(ResponseBody);
|
Log.setResponseBody(ResponseBody);
|
||||||
|
try {
|
||||||
SQLiteWriteLock.lock();
|
SQLiteWriteLock.lock();
|
||||||
AccessLogRepository.save(Log);
|
AccessLogRepository.save(Log); }
|
||||||
SQLiteWriteLock.unlock();
|
catch (Exception e) {
|
||||||
|
log.error(e.getLocalizedMessage()); }
|
||||||
|
finally {
|
||||||
|
SQLiteWriteLock.unlock(); }
|
||||||
Response.copyBodyToResponse(); } }
|
Response.copyBodyToResponse(); } }
|
||||||
Reference in New Issue
Block a user