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

src: more debug statements #708

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ function session(options) {
return function session(req, res, next) {
// self-awareness
if (req.session) {
debug('re-using existing session')
next()
return
}
Expand Down Expand Up @@ -302,13 +303,13 @@ function session(options) {

if (shouldDestroy(req)) {
// destroy session
debug('destroying');
debug('destroying session');
dougwilson marked this conversation as resolved.
Show resolved Hide resolved
store.destroy(req.sessionID, function ondestroy(err) {
if (err) {
defer(next, err);
}

debug('destroyed');
debug('session destroyed');
dougwilson marked this conversation as resolved.
Show resolved Hide resolved
writeend();
});

Expand Down Expand Up @@ -357,6 +358,7 @@ function session(options) {

// generate the session
function generate() {
debug('session generate');
dougwilson marked this conversation as resolved.
Show resolved Hide resolved
store.generate(req);
originalId = req.sessionID;
originalHash = hash(req.session);
Expand Down Expand Up @@ -393,6 +395,7 @@ function session(options) {
debug('saving %s', this.id);
savedHash = hash(this);
_save.apply(this, arguments);
debug('session saved');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This prints before the session is saved, as the saving operation is async.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is based on I am assuming that this line is desired to be similar to the destroy logs, with the behavior of "destroying.." being logged before the store call and then "... destroyed" called when the store returns back to this module without an error.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @dougwilson . yes, the desire is to follow destroy. the intent is simple - many issues in this repo are about session not being saved or inability to know about it.

thinking about it more, I can achieve this at the save site only via structural changes to the save function. that is, anchoring the save call with a custom callback, check for errors, or else print the debug message and then invoke the original callback, if any.

Before implementing it and submitting for your review, I want to pro-actively check with you on it - will you be open for such a change?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @gireeshpunathil yes, that sounds good to me, to just mimic the destroy way in the save area.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dougwilson - done, pls have a look. Here is a sample output from a simple program with debug on, for your reference:

  express-session fetching qs3pPenGDQy0hOXWCw_G8lD_ZLJw5AA1 +0ms
  express-session no session found +5ms
  express-session session generate +1ms
  express-session saving 7G28RiMV20yaNOzU3UeC5_qJMKek7X6f +4ms
  express-session set-cookie connect.sid=s%XXX; Path=/; Expires=YYY; HttpOnly +4ms
  express-session session saved +3ms

}

Object.defineProperty(sess, 'reload', {
Expand Down