Hi Bernardo,

Thanks for your answer.

I was half way through doing this, when I read this:

https://github.com/nodejs/node/issues/2642

How do you deal with keepalive connections? They can potentially stay up 
forever (if they ping often enough) even after close() has been issued...

Processing payments outside the app is probably a very good idea. The queue 
could be as simple as a database table... but, one question: once the 
transaction is done, how would the "CC app" let the main app know that the 
transaction has happened?

Merc.,


On Wednesday, 1 March 2017 09:41:59 UTC+8, Bernardo wrote:
>
> Tony,
>
> We have pretty much the same solution you described implemented in our 
> app, except for the 10s timeout, and it works very well. 
>
> You don't have to do anything special to check the event loop, if you call 
> the close method on all your active servers the process will end when all 
> connections have drained.
>
> That said, wouldn't it be wiser to move the credit card handling out of 
> the main app? You could have the main app fill a queue with pending 
> transactions and have the CC app consume the queue, that way the worst that 
> can happen is a delay in processing  a transaction rather than it vanishing 
> into to the ether.
>
> On Tue, Feb 28, 2017 at 4:23 AM, Tony Mobily <tonym...@gmail.com 
> <javascript:>> wrote:
>
>> I have a very, very busy node application on a production server. The app 
>> deals with a real-time chat (using websockets) as well as e-commerce 
>> payments. While *everything* is absolutely set so that when the server 
>> goes down the clients will reconnect their sockets etc., I still have a 
>> problem: whenever the server is stopped, with a SIGINT, the event loop is 
>> cut off. This means that any pending DB write (possibly for a financial 
>> transaction) is simply discarded. There are two especially crucial moments 
>> (when the credit card merchant gives the OK, but *before* we write the 
>> record on the db) and at the moment we are shutting it down at off-peak 
>> times to prevent any possible problems. But this is bad.
>>
>> I am thinking of this as a solution:
>>
>>    - I send a custom UNIX signal to the process (SIGUSR2 for example?);
>>    - When server.js gets the signal:
>>       - It stops listening to port 80
>>       - It waits for the event loop to dry up
>>       - If after 10 seconds it's still hanging, it forces the closure 
>>       This means that at each reboot the server will be at the most down for 
>> 10 
>>       seconds.
>>    
>> Is this what people in the real world do? Any gotcha? How do I check that 
>> the event loop is empty?
>>
>>
>> -- 
>> Job board: http://jobs.nodejs.org/
>> New group rules: 
>> https://gist.github.com/othiym23/9886289#file-moderation-policy-md
>> Old group rules: 
>> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
>> --- 
>> You received this message because you are subscribed to the Google Groups 
>> "nodejs" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to nodejs+un...@googlegroups.com <javascript:>.
>> To post to this group, send email to nod...@googlegroups.com 
>> <javascript:>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/nodejs/2058de6b-d042-4e82-b3ea-b1379e9d721e%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/nodejs/2058de6b-d042-4e82-b3ea-b1379e9d721e%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to nodejs+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/02776995-d940-4156-9e1c-0abe8dd7ad2b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to