Repository: stripe/stripe-node (ts)

Issue:
Default http timeout changed in Node 13
In Node.js v13.0.0 [the default socket timeout has been set to 0](https://github.com/nodejs/node/pull/27558).

Currently in this Library the default timeout is being set based on [`require('http').createServer().timeout`](https://github.com/stripe/stripe-node/blob/1a6cd581514de22d1561ae68c2401a168485c07d/lib/stripe.js#L11).
https://github.com/stripe/stripe-node/blob/1a6cd581514de22d1561ae68c2401a168485c07d/lib/stripe.js#L11
 The default previously was 120 seconds, under v13 it is no timeout by default aka a value of `0`.

I noticed this when looking into https://github.com/stripe/stripe-node/issues/796

I haven't done any testing with this so I don't know if it represents an actual bug, but wanted to file this issue in case this was something the team was unaware of. 

This timeout was introduced in Node.js v0.9.12 as 120 seconds, and did not change until v13.0.0 when it was switched to 0. There is of course a possibility that this change will be reverted before v14 is released, but it's worth keeping an eye on.

Pull request:
Change timeout default to constant 80000 instead Node default
Closes #806 

Set `timeout` default to a constant 80 seconds instead of using the default value of the version of Node.js the user is running.

Updated tests, docs, comment in types def file.

**Note**: Not sure how you define breaking changes here, but this would be a departure from the previous default behavior of 120 seconds. This issue is currently out in the wild though (for anyone _\*brave\*_ enough to be using v13 in production) so I would suggest a release as soon as feasible. 

Switching this back to a constant 120 seconds and a minor version bump would prevent anyone from encountering the issue in the current major.

Patch:
diff --git a/README.md b/README.md
index 1c64a751..fc6d74a6 100644
--- a/README.md
+++ b/README.md
@@ -165,15 +165,15 @@ const stripe = Stripe('sk_test_...', {
 });
 ```
 
-| Option              | Default                       | Description                                                                           |
-| ------------------- | ----------------------------- | ------------------------------------------------------------------------------------- |
-| `apiVersion`        | `null`                        | Stripe API version to be used. If not set the account's default version will be used. |
-| `maxNetworkRetries` | 0                             | The amount of times a request should be [retried](#network-retries).                  |
-| `httpAgent`         | `null`                        | [Proxy](#configuring-a-proxy) agent to be used by the library.                        |
-| `timeout`           | 120000 (Node default timeout) | [Maximum time each request can take in ms.](#configuring-timeout)                     |
-| `host`              | `'api.stripe.com'`            | Host that requests are made to.                                                       |
-| `port`              | 443                           | Port that requests are made to.                                                       |
-| `telemetry`         | `true`                        | Allow Stripe to send latency [telemetry](#request-latency-telemetry).                 |
+| Option              | Default            | Description                                                                           |
+| ------------------- | ------------------ | ------------------------------------------------------------------------------------- |
+| `apiVersion`        | `null`             | Stripe API version to be used. If not set the account's default version will be used. |
+| `maxNetworkRetries` | 0                  | The amount of times a request should be [retried](#network-retries).                  |
+| `httpAgent`         | `null`             | [Proxy](#configuring-a-proxy) agent to be used by the library.                        |
+| `timeout`           | 80000              | [Maximum time each request can take in ms.](#configuring-timeout)                     |
+| `host`              | `'api.stripe.com'` | Host that requests are made to.                                                       |
+| `port`              | 443                | Port that requests are made to.                                                       |
+| `telemetry`         | `true`             | Allow Stripe to send latency [telemetry](#request-latency-telemetry).                 |
 
 Note: Both `maxNetworkRetries` and `timeout` can be overridden on a per-request basis.
 
diff --git a/lib/stripe.js b/lib/stripe.js
index 5b7bace5..929a7915 100644
--- a/lib/stripe.js
+++ b/lib/stripe.js
@@ -7,8 +7,7 @@ const DEFAULT_PORT = '443';
 const DEFAULT_BASE_PATH = '/v1/';
 const DEFAULT_API_VERSION = null;
 
-// Use node's default timeout:
-const DEFAULT_TIMEOUT = require('http').createServer().timeout;
+const DEFAULT_TIMEOUT = 80000;
 
 Stripe.PACKAGE_VERSION = require('../package.json').version;
 
diff --git a/types/lib.d.ts b/types/lib.d.ts
index af45c9ba..0f2010bf 100644
--- a/types/lib.d.ts
+++ b/types/lib.d.ts
@@ -44,7 +44,7 @@ declare module 'stripe' {
 
       /**
        * Request timeout in milliseconds.
-       * The default is Node's default of 120 seconds.
+       * The default is 80000
        */
       timeout?: number;
 


Test patch:
diff --git a/test/stripe.spec.js b/test/stripe.spec.js
index 9ee80974..dc927c0e 100644
--- a/test/stripe.spec.js
+++ b/test/stripe.spec.js
@@ -7,8 +7,6 @@ const utils = require('../lib/utils');
 const Stripe = require('../lib/stripe');
 const stripe = require('../lib/stripe')(testUtils.getUserStripeKey(), 'latest');
 
-const http = require('http');
-
 const expect = require('chai').expect;
 
 const CUSTOMER_DETAILS = {
@@ -208,10 +206,9 @@ describe('Stripe Module', function() {
   });
 
   describe('setTimeout', () => {
-    it('Should define a default equal to the node default', () => {
-      expect(stripe.getApiField('timeout')).to.equal(
-        http.createServer().timeout
-      );
+    const defaultTimeout = 80000;
+    it('Should define a default of 80000', () => {
+      expect(stripe.getApiField('timeout')).to.equal(defaultTimeout);
     });
     it('Should allow me to set a custom timeout', () => {
       stripe.setTimeout(900);
@@ -219,9 +216,7 @@ describe('Stripe Module', function() {
     });
     it('Should allow me to set null, to reset to the default', () => {
       stripe.setTimeout(null);
-      expect(stripe.getApiField('timeout')).to.equal(
-        http.createServer().timeout
-      );
+      expect(stripe.getApiField('timeout')).to.equal(defaultTimeout);
     });
   });