XX系統中,一個用戶須要維護的項目數過多,填寫的任務數超多,產生了一次工時保存中,只有前面一部分的xx數據持久化到數據庫,後面的數據沒有保存。前端
圖1
java
首先想到的是否後面部分的數據在保存過程當中發生了異常。排查異常日誌,發現沒有該問題存在。nginx
而後增長方法參數信息日誌,數據參數信息。發現參數集合size=200,前端發送集合size=400。判斷問題能夠能是由於服務器容器環境(Nginx+Tomcat)致使web
在測試環境模擬線上數據。如圖1
spring
在idea中直接啓動tomcat,無nginx環境,若是沒有問題,則可暫時肯定爲nginx問題。數據庫
然而,在過程當中發現了新的問題。tomcat
org.springframework.beans.InvalidPropertyException: Invalid property 'detail[256]' of bean class [com.suning.asvp.mer.entity.InviteCooperationInfo]: Index of out of bounds in property path 'detail[256]'; nested exception is java.lang.IndexOutOfBoundsException: Index: 256, Size: 256 at org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:833) ~[spring-beans-3.1.2.RELEASE.jar:3.1.2.RELEASE] at org.springframework.beans.BeanWrapperImpl.getNestedBeanWrapper(BeanWrapperImpl.java:576) ~[spring-beans-3.1.2.RELEASE.jar:3.1.2.RELEASE] at org.springframework.beans.BeanWrapperImpl.getBeanWrapperForPropertyPath(BeanWrapperImpl.java:553) ~[spring-beans-3.1.2.RELEASE.jar:3.1.2.RELEASE] at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:914) ~[spring-beans-3.1.2.RELEASE.jar:3.1.2.RELEASE] at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:76) ~[spring-beans-3.1.2.RELEASE.jar:3.1.2.RELEASE] at org.springframework.validation.DataBinder.applyPropertyValues(DataBinder.java:692) ~[spring-context-3.1.2.RELEASE.jar:3.1.2.RELEASE] at org.springframework.validation.DataBinder.doBind(DataBinder.java:588) ~[spring-context-3.1.2.RELEASE.jar:3.1.2.RELEASE] at org.springframework.web.bind.WebDataBinder.doBind(WebDataBinder.java:191) ~[spring-web-3.1.2.RELEASE.jar:3.1.2.RELEASE] at org.springframework.web.bind.ServletRequestDataBinder.bind(ServletRequestDataBinder.java:112) ~[spring-web-3.1.2.RELEASE.jar:3.1.2.RELEASE]
查看BeanWrapperImpl源碼服務器
else if (value instanceof List) { int index = Integer.parseInt(key); List list = (List) value; growCollectionIfNecessary(list, index, indexedPropertyName, pd, i + 1); value = list.get(index);// 測試報錯時,此處list只有256個,index爲256時,取第257個報錯 }
@SuppressWarnings("unchecked") private void growCollectionIfNecessary( Collection collection, int index, String name, PropertyDescriptor pd, int nestingLevel) { if (!this.autoGrowNestedPaths) { return; } int size = collection.size(); // 當個數小於autoGrowCollectionLimit這個值時纔會向list中添加新元素 if (index >= size && index < this.autoGrowCollectionLimit) { Class elementType = GenericCollectionTypeResolver.getCollectionReturnType(pd.getReadMethod(), nestingLevel); if (elementType != null) { for (int i = collection.size(); i < index + 1; i++) { collection.add(newValue(elementType, name)); } } } }
根據上面的分析找到autoGrowCollectionLimit的定義app
public class DataBinder implements PropertyEditorRegistry, TypeConverter { /** Default object name used for binding: "target" */ public static final String DEFAULT_OBJECT_NAME = "target"; /** Default limit for array and collection growing: 256 */ public static final int DEFAULT_AUTO_GROW_COLLECTION_LIMIT = 256; private int autoGrowCollectionLimit = DEFAULT_AUTO_GROW_COLLECTION_LIMIT;
解決方案,是在本身的Controller中加入以下方法ide
@InitBinder protected void initBinder(WebDataBinder binder) { binder.setAutoGrowNestedPaths(true); binder.setAutoGrowCollectionLimit(1024); }
==BUT 這個問題和線上的不一樣,只能算是意外收穫。革命還沒有成功,同志仍需努力!!!!==
通過2.2的奮鬥,暫時斷定是否爲Nginx post請求參數作了限制。嗯,開搞~ 在開發環境配置Nginx代理,過程略·····
nginx.conf 以下
upstream xxxxxxx { server 127.0.0.1:8080 weight=10 max_fails=2 fail_timeout=30s ; } server { listen 80; server_name xxxxxxx.com; client_max_body_size 100M; # 配置post size #charset koi8-r; #access_log logs/host.access.log main; location / { #proxy_next_upstream http_500 http_502 http_503 http_504 error timeout invalid_header; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://xxxxxxx; expires 0; } }
對於client_max_body_size 100M;
,網上都是與文件上傳相關的。不過都是經過post, request body的方式上傳數據,因此通用。
測試~~
功能正常,沒有重現線上問題。 哭死~~~
革命還要繼續~~
去線上服務器拉去配置
<Connector port="1601" maxParameterCount="1000" protocol="HTTP/1.1" redirectPort="8443" maxSpareThreads="750" maxThreads="1000" minSpareTHreads="50" acceptCount="1000" connectionTimeout="20000" URIEncoding="utf-8"/>
經分析,發現線上沒有body size的配置,卻有maxParameterCount="1000"
。該參數爲限制請求的參數個數,從而變相限制body size。
在開發環境配置該參數,測試,問題重現。
問題緣由定位好了,剩下的就是如何解決了。
兩個方案:
該上實施難度係數高,由於公司使用的統一發布部署平臺,開發人員無服務器操做權限。
修改保存邏輯,分片存儲
問題排查,須要先對總體有個把握,而後分析影響範圍。不能鑽牛角尖,採用西醫「頭疼醫頭」的方式。有可能最後結果仍是要醫頭,但此時的醫頭已是創建在中醫的辯證主義上,對症下藥。