|
2 | 2 |
|
3 | 3 | The MIT License (MIT) |
4 | 4 |
|
5 | | - Copyright (c) 2015-2016 Telefónica Investigación y Desarrollo, S.A.U |
| 5 | + Copyright (c) 2015-2018 Telefónica Investigación y Desarrollo, S.A.U |
6 | 6 |
|
7 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy |
8 | 8 | of this software and associated documentation files (the "Software"), to deal |
@@ -55,19 +55,20 @@ function enableTerminate(server, opts) { |
55 | 55 | }); |
56 | 56 |
|
57 | 57 | server.on('request', function onRequest(req, res) { |
| 58 | + var connId = req.socket.id || req.socket._parent.id; // On SSL connections the TLS socket inherits from the original socket |
58 | 59 | // Increase the number of running requests over the related connection |
59 | | - connections[req.socket.id].runningRequests++; |
| 60 | + connections[connId].runningRequests++; |
60 | 61 |
|
61 | 62 | res.on('finish', function onFinish() { |
62 | 63 | // Decrease the number of running requests over the related connection |
63 | 64 | // (only if the socket has not been previously closed) |
64 | | - if (connections[req.socket.id]) { |
65 | | - connections[req.socket.id].runningRequests--; |
| 65 | + if (connections[connId]) { |
| 66 | + connections[connId].runningRequests--; |
66 | 67 | // If this event happens after the "terminate" function has been invoked, it means that we are waiting |
67 | 68 | // for running requests to finish, so close the connection as soon as the requests finish |
68 | | - if (terminating && !connections[req.socket.id].runningRequests) { |
69 | | - connections[req.socket.id].conn.destroy(); |
70 | | - delete connections[req.socket.id]; |
| 69 | + if (terminating && !connections[connId].runningRequests) { |
| 70 | + connections[connId].conn.destroy(); |
| 71 | + delete connections[connId]; |
71 | 72 | } |
72 | 73 | } |
73 | 74 | }); |
|
0 commit comments