Skip to content

Fixes Issue #543 - Provider does not shutdown when told#551

Open
DJHoltkamp wants to merge 7 commits intonode-apn:mainfrom
CrimsonMoonEntertainment:master
Open

Fixes Issue #543 - Provider does not shutdown when told#551
DJHoltkamp wants to merge 7 commits intonode-apn:mainfrom
CrimsonMoonEntertainment:master

Conversation

@DJHoltkamp
Copy link
Copy Markdown

When used locally or on AWS Lambda, the provider holds the process running with the heartbeat timer. This turns off the timer on close

@coveralls
Copy link
Copy Markdown

coveralls commented Apr 3, 2017

Coverage Status

Coverage remained the same at 100.0% when pulling f025219 on CrimsonMoonEntertainment:master into a024d3d on node-apn:master.

@DJHoltkamp
Copy link
Copy Markdown
Author

DJHoltkamp commented Apr 4, 2017

I have noted an extra issue I found when using this library. I think it might have cropped up due to me getting rid of the timer at the correct time. In our aws lambda function, we shutdown the connection a lot and then it gets re-opened. Lambda also keeps the function alive between calls many times. Somehow in this environment, we frequently have our code execute as follows:

       console.log('starting send');
        provider.send(noteToSend, token).then( function (result)
        {
            console.log('send finished');
       });

Where "started send" shows, but then lambda stops the function before "send finished" without any function error, signifying that there were no more threads/processes running. I am not really up to speed on sockets with Node.js so I am not sure how to go about debugging it. I only mention it here because it could be related to this fix. Before, the heartbeat timer would cause it to continue on, but also, as my issue says incorrectly keeps the function around for another minute.

@DJHoltkamp
Copy link
Copy Markdown
Author

Ok, so I drilled down in the code a bit further. My ES6 promise knowledge is no where near good, but here is a possible issue in client.js

  Client.prototype.getStream = function getStream() {
    return new Promise( resolve => {
      const stream = this.endpointManager.getStream();
      if (!stream) {
        this.queue.push(resolve);
      } else {
        resolve(stream);
      }
    });
  };

You'll notice here, it seems to just push this into the queue and not resolve anything. In my case, where the promise is not being met, would this not cause there to be 0 processes running, hence my termination from lambda? Not sure who was supposed to send this "Wakeup" call, but if it was the heartbeat timer, then you are kind of screwed if you already shutdown() even once like I have. Thoughts?

@martijndeh
Copy link
Copy Markdown

@DJHoltkamp I ran into the same issue and think I fixed it in #554. What do you think?

@DJHoltkamp
Copy link
Copy Markdown
Author

I'd have to try it out in production, but it looks like it may fix it.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants