Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: unable to find the session to touch on 4.1.0 #390

Closed
barisusakli opened this issue Feb 22, 2021 · 13 comments
Closed

Error: unable to find the session to touch on 4.1.0 #390

barisusakli opened this issue Feb 22, 2021 · 13 comments

Comments

@barisusakli
Copy link

  • I'm submitting a ...
    [*] bug report

  • Summary
    It seems like when res.send is called the touch method is triggered and the following code tries to update the session object. But there are no changes so modifiedCount is 0 and it throws an error.

 const rawResp = await collection.updateOne({ _id: this.computeStorageId(sid) }, { $set: updateFields }, this.options.writeOperationOptions);
                if (rawResp.modifiedCount === 0) {
                    return callback(new Error('Unable to find the session to touch'));
                }
2021-02-22T21:38:48.684Z [4567/13400] - error: /assets/src/modules/jquery-ui/widgets/autocomplete.js
Error: Unable to find the session to touch
    at nodebb_master\node_modules\connect-mongo\build\main\lib\MongoStore.js:285:37
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)

Which leads to

 Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
    at ServerResponse.setHeader (_http_outgoing.js:536:11)
    at ServerResponse.header (nodebb_master\node_modules\express\lib\response.js:771:10)
    at ServerResponse.send (nodebb_master\node_modules\express\lib\response.js:170:12)
    at ServerResponse.renderOverride [as render] (nodebb_master\src\middleware\render.js:79:11)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:93:5) {

Let me know if you need more info.

@barisusakli
Copy link
Author

Some more info, this is happening on a cold load where express is also serving static assets. So a single cold load is triggering the touch function about 60 times. Out of those ~5 of them are failing with this error message because they use the same updateFields for the update function.

I tried adding touchAfter: 5000 to see if it would make a difference but that code block is never executed because session.lastModified is always 0.

@barisusakli barisusakli changed the title Error: unabled to find the session to touch on 4.1.0 Error: unable to find the session to touch on 4.1.0 Feb 22, 2021
@mingchuno
Copy link
Collaborator

mingchuno commented Feb 23, 2021

touchAfter should work ... But I wonder why the touch function will be trigger 60 times on a cold start. Do you have a simple reproduceable build? What env / set up are you running on?

@barisusakli
Copy link
Author

@mingchuno hello, what I meant by cold load is when I hit f5 to reload the home page of the app. It is not during nodejs application start. When I do a reload the browser makes a lot of requests to load all the assets and each of these requests calls res.send which triggers touch and some of them try to update the mongodb object with the same data so they get back modifiedCount=0. I checked the database and the session object is definitely there so the unable to find session to touch error is a bit misleading.

@mingchuno
Copy link
Collaborator

@barisusakli Changing from modifiedCount to matchedCount should fix the issue. Let me create a PR

@mingchuno
Copy link
Collaborator

@barisusakli I also would like to invistigate why the touchAfter not working as expected

@barisusakli
Copy link
Author

@mingchuno when I was debugging it earlier the session object never had a lastModified value so it was never going into the if statement here https://github.com/jdesboeufs/connect-mongo/blob/master/src/lib/MongoStore.ts#L360

@mingchuno
Copy link
Collaborator

@barisusakli I have changed the modifiedCount to matchedCount. Please test with npm install connect-mongo@next. For the missing lastModified, I will investigate later.

@barisusakli
Copy link
Author

This error is gone on @next after the matchedCount change

Error: Unable to find the session to touch
    at nodebb_master\node_modules\connect-mongo\build\main\lib\MongoStore.js:285:37
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)

Thanks.

@barisusakli
Copy link
Author

barisusakli commented Feb 23, 2021

I don't know if this is related but I got the below error but it was random, couldn't get it again.

TypeError: Cannot read property 'lastModified' of null
    at nodebb_master\node_modules\connect-mongo\build\main\lib\MongoStore.js:174:60
    at processTicksAndRejections (internal/process/task_queues.js:93:5)

At that line the session variable is null. It happened when I tried logging in.

@mingchuno
Copy link
Collaborator

okay. Let me take a look later. You can also help to take a look on the root cause if you are available 🙏🏻

@mingchuno
Copy link
Collaborator

This commit should fix the issue 46a40db

@barisusakli
Copy link
Author

@mingchuno thanks

@iamodreck
Copy link

I don't know if this is related but I got the below error but it was random, couldn't get it again.

TypeError: Cannot read property 'lastModified' of null
    at nodebb_master\node_modules\connect-mongo\build\main\lib\MongoStore.js:174:60
    at processTicksAndRejections (internal/process/task_queues.js:93:5)

At that line the session variable is null. It happened when I tried logging in.

Try restarting the server your using before carrying out that task

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants