POST DOCUMENTS RANDOM ERROR
WT2 opened this issue · 7 comments
Hello Guys
restheart:7.3.2 / 7.3.3
mongo:6.0
Sorry guys to bother you.. i have POST to create documents random error.
I am wondering if this is not due to the fact that i use mongo6, and you maybe fully support mongo5 at this time.
Do you advise me to use mongo5 rather than 6? Thanks
Here is the exception:
12:45:10.477 [XNIO-1 task-5] ^[[1;31mERROR^[[0;39m o.r.mongodb.handlers.ErrorHandler - Error handling the request
java.lang.NullPointerException: Cannot invoke "org.bson.BsonDocument.get(Object)" because the return value of "org.restheart.mongodb.db.OperationResult.getNewData()" is null
at org.restheart.mongodb.handlers.collection.PostCollectionHandler.handleRequest(PostCollectionHandler.java:155)
at org.restheart.mongodb.handlers.NormalOrBulkDispatcherHandler.handleRequest(NormalOrBulkDispatcherHandler.java:64)
at org.restheart.mongodb.handlers.RequestDispatcherHandler.handleRequest(RequestDispatcherHandler.java:135)
at org.restheart.handlers.PipelinedHandler.next(PipelinedHandler.java:80)
at org.restheart.mongodb.handlers.injectors.ETagPolicyInjector.handleRequest(ETagPolicyInjector.java:73)
at org.restheart.handlers.PipelinedHandler.next(PipelinedHandler.java:80)
at org.restheart.mongodb.handlers.injectors.ClientSessionInjector.handleRequest(ClientSessionInjector.java:99)
at org.restheart.handlers.PipelinedHandler.next(PipelinedHandler.java:80)
at org.restheart.mongodb.handlers.OptionsHandler.handleRequest(OptionsHandler.java:83)
at org.restheart.mongodb.handlers.ErrorHandler.handleRequest(ErrorHandler.java:74)
at org.restheart.handlers.PipelinedWrappingHandler.handleRequest(PipelinedWrappingHandler.java:121)
at io.undertow.server.handlers.PathHandler.handleRequest(PathHandler.java:104)
at org.restheart.handlers.PipelinedWrappingHandler.handleRequest(PipelinedWrappingHandler.java:121)
at org.restheart.mongodb.MongoService.handle(MongoService.java:126)
at org.restheart.mongodb.MongoService.handle(MongoService.java:72)
at org.restheart.handlers.ServiceWrapper.handleRequest(PipelinedWrappingHandler.java:139)
at org.restheart.handlers.PipelinedWrappingHandler.handleRequest(PipelinedWrappingHandler.java:121)
at io.undertow.server.handlers.encoding.EncodingHandler.handleRequest(EncodingHandler.java:72)
at org.restheart.handlers.ConfigurableEncodingHandler.handleRequest(ConfigurableEncodingHandler.java:81)
at org.restheart.handlers.PipelinedWrappingHandler.handleRequest(PipelinedWrappingHandler.java:121)
at org.restheart.handlers.PipelinedHandler.next(PipelinedHandler.java:80)
at org.restheart.handlers.QueryStringRebuilder.handleRequest(QueryStringRebuilder.java:92)
at org.restheart.handlers.PipelinedHandler.next(PipelinedHandler.java:80)
at org.restheart.handlers.RequestInterceptorsExecutor.handleRequest(RequestInterceptorsExecutor.java:149)
at org.restheart.handlers.PipelinedHandler.next(PipelinedHandler.java:80)
at org.restheart.security.handlers.AuthorizersHandler.handleRequest(AuthorizersHandler.java:65)
at org.restheart.handlers.PipelinedHandler.next(PipelinedHandler.java:80)
at org.restheart.handlers.injectors.TokenInjector.handleRequest(TokenInjector.java:62)
at org.restheart.handlers.PipelinedHandler.next(PipelinedHandler.java:80)
at org.restheart.security.handlers.AuthenticationCallHandler.handleRequest(AuthenticationCallHandler.java:110)
at org.restheart.handlers.PipelinedHandler.next(PipelinedHandler.java:80)
at org.restheart.security.handlers.AuthenticationConstraintHandler.handleRequest(AuthenticationConstraintHandler.java:79)
at org.restheart.handlers.PipelinedHandler.next(PipelinedHandler.java:80)
at org.restheart.security.handlers.AuthenticatorMechanismsHandler.handleRequest(AuthenticatorMechanismsHandler.java:59)
at org.restheart.handlers.PipelinedHandler.next(PipelinedHandler.java:80)
at org.restheart.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:74)
at org.restheart.handlers.PipelinedHandler.next(PipelinedHandler.java:80)
at org.restheart.security.handlers.SecurityHandler.handleRequest(SecurityHandler.java:58)
at org.restheart.handlers.PipelinedHandler.next(PipelinedHandler.java:80)
at org.restheart.handlers.QueryStringRebuilder.handleRequest(QueryStringRebuilder.java:92)
at org.restheart.handlers.PipelinedHandler.next(PipelinedHandler.java:80)
at org.restheart.handlers.RequestInterceptorsExecutor.handleRequest(RequestInterceptorsExecutor.java:149)
at org.restheart.handlers.PipelinedHandler.next(PipelinedHandler.java:80)
at org.restheart.handlers.injectors.XPoweredByInjector.handleRequest(XPoweredByInjector.java:63)
at org.restheart.handlers.PipelinedHandler.next(PipelinedHandler.java:80)
at org.restheart.handlers.CORSHandler.handleRequest(CORSHandler.java:90)
at org.restheart.handlers.PipelinedHandler.next(PipelinedHandler.java:80)
at org.restheart.handlers.ServiceExchangeInitializer.handleRequest(ServiceExchangeInitializer.java:103)
at org.restheart.handlers.PipelinedHandler.next(PipelinedHandler.java:80)
at org.restheart.handlers.BeforeExchangeInitInterceptorsExecutor.handleRequest(BeforeExchangeInitInterceptorsExecutor.java:85)
at org.restheart.handlers.PipelinedHandler.next(PipelinedHandler.java:80)
at org.restheart.handlers.RequestLogger.handleRequest(RequestLogger.java:86)
at org.restheart.handlers.PipelinedHandler.next(PipelinedHandler.java:80)
at org.restheart.handlers.TracingInstrumentationHandler.handleRequest(TracingInstrumentationHandler.java:62)
at org.restheart.handlers.PipelinedHandler.next(PipelinedHandler.java:80)
at org.restheart.handlers.WorkingThreadsPoolDispatcher.handleRequest(WorkingThreadsPoolDispatcher.java:70)
at org.restheart.handlers.ErrorHandler.handleRequest(ErrorHandler.java:61)
at io.undertow.server.Connectors.executeRootHandler(Connectors.java:393)
at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:859)
at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2513)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1538)
at org.xnio.XnioWorker$WorkerThreadFactory$1$1.run(XnioWorker.java:1282)
at java.base/java.lang.Thread.run(Unknown Source)
12:45:10.478 [XNIO-1 task-5] ^[[34mINFO ^[[0;39m org.restheart.handlers.RequestLogger - POST http://api_dynamic/api/test_database/test_collection from /192.168.16.3:34658 => status=^[[31;1m500^[[m elapsed=10ms contentLength=251 username=opsbatch roles=[base]
HERE IS THE REQUEST
--> CREATE DOCUMENT
REQUEST METHOD POST
REQUEST URL https://XXXXXXXXXXXXX/api/test_database/test_collection
REQUEST HEADERS {'Content-Length': '44', 'X-Is-CloudRun': 'TRUE', 'accept': '*/*', 'User-Agent': 'python-requests/2.27.1', 'Connection': 'keep-alive', 'X-Was-LoadBalanced': 'TRUE', 'content-type': 'application/json', 'Authorization': 'XXXXXXXXXXXXXXX', 'Accept-Encoding': 'gzip, deflate'}
REQUEST BODY {"last": "L6FZLM9KPN", "name": "CB9GFN3X1Z"}
RESPONSE HEADERS {'X-XSS-Protection': '1; mode=block', 'Content-Length': '251', 'Strict-Transport-Security': 'max-age=31536000; includeSubDomains; preload', 'Auth-Token-Location': '/tokens/opsbatch', 'Auth-Token-Valid-Until': '2023-03-27T12:57:24.100095577Z', 'Content-Encoding': 'gzip', 'Access-Control-Expose-Headers': 'Location, ETag, Auth-Token, Auth-Token-Valid-Until, Auth-Token-Location, X-Powered-By', 'Content-Security-Policy': "default-src 'self' https: wss: data: blob: 'unsafe-inline';", 'X-Powered-By': 'origin', 'Server': 'nginx', 'Auth-Token': 'XXXXXXXXXXXXX', 'X-Content-Type-Options': 'nosniff', 'Connection': 'keep-alive', 'ETag': '64218f3074725420de5849a6', 'Access-Control-Allow-Credentials': 'true', 'Date': 'Mon, 27 Mar 2023 12:42:24 GMT', 'Access-Control-Allow-Origin': '*', 'Referrer-Policy': 'strict-origin-when-cross-origin', 'Content-Type': 'application/json', 'X-Frame-Options': 'DENY', 'Permissions-Policy': 'interest-cohort=()'}
RESPONSE COOKIES {}
RESPONSE CONTENT {"http status code":500,"http status description":"Internal Server Error","message":"Error handling the request, see log for more information","exception":"java.lang.NullPointerException","exception message":"Cannot invoke 'org.bson.BsonDocument.get(Object)' because the return value of 'org.restheart.mongodb.db.OperationResult.getNewData()' is null"}
RESPONSE STATUS CODE 500
RESPONSE ERROR MESSAGE Internal Server Error - Error handling the request, see log for more information
CREATED False
UPDATED False
DELETED False
RETRIEVED False
SUCCESS False
ID None
ETAG 64218f3074725420de5849a6
We support MongoDB 6
I cannot reproduce.
Nevertheless I refactored the code to avoid the NullPointerException in that line, even if it is weird that you get a document inserted but no data from the MongoDB java driver (thus thew NPE)
Can you try with the following snapshot image
$ docker pull softinstigate/restheart-snapshot:45955fb
Hi @ujibang
YES! thanks it corrects. I set this snapshot only on one of my two nodes. i still reproduce on the node with 7.3.3 and no longer on the snapshot 45955fb! so your refactor worked! i no longer have that error.
Actually i just realized that i was getting this with RESTHEART default readPreference set to secondaryPreffered.
When i put it back to primaryPreferred, i do not reproduce.
So if you want to reproduce, you set in your restheart settings MONGO_URI secondaryPreffered.
You confirm?
I just discovered some other bugs with secondaryPreffered as default, i can share them with you if you like.
yes please share all the bugs you find.
hello,
do you confirm this has been taken into account in 7.3.4?
thanks
yes, this fix is in 7.3.4