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

Connection lost - Cannot call write after a stream was destroyed #903

Closed
irgijs opened this issue May 24, 2019 · 14 comments
Closed

Connection lost - Cannot call write after a stream was destroyed #903

irgijs opened this issue May 24, 2019 · 14 comments

Comments

@irgijs
Copy link

irgijs commented May 24, 2019

Since tedious version 2.7.0 the following error event is emitted. This error is still emitted in the newest release (v6.1.1):

Connection lost - Cannot call write after a stream was destroyed

We tested this with both SQL Server 2016 and 2017. We are still trying to reproduce the error and we will report back if we found something.

@irgijs
Copy link
Author

irgijs commented May 27, 2019

Additional information:

  • I found the specific commit which introduces the error: 908488a
  • We use the tedious connection pool (modified in fork in such a way that tedious is used as peer dependency)

@arthurschreiber
Copy link
Collaborator

@irgijs There's a bunch of connection lifecycle issues in current and older tedious releases, plus the connection pool code does not handle lifecycle issues well either. 😞

I did some work that was targeted at improving the situation over at https://github.com/tediousjs/tedious/compare/arthur/rework-connection-close, but I never finished turning it into a proper PR. Seeing the issues you're running into makes me think I should revive that branch and finish the work there. 🙇

Would you mind also sharing the modifications you made to the connection pool code? 😬

@irgijs
Copy link
Author

irgijs commented May 27, 2019

@arthurschreiber We only changed the package.json file to so that it would accept any tedious release (as peer dependency):

{
	"name": "tedious-connection-pool",
	"version": "1.0.0",
	"description": "Connection Pool for tedious.",
	"main": "lib/connection-pool.js",
	"scripts": {
		"test": "node_modules/.bin/mocha --expose-gc test/test.js"
	},
	"repository": {
		"type": "git",
		"url": "https://bitbucket.org/irefact/tedious-connection-pool.git"
	},
	"keywords": [
		"tedious",
		"connection",
		"pool"
	],
	"author": {
		"name": "Ben Page",
		"email": "[email protected]"
	},
	"contributors": [
		{
			"name": "Ben Page",
			"email": "[email protected]"
		},
		{
			"name": "Mike D Pilsbury",
			"email": "[email protected]"
		}
	],
	"license": "MIT",
	"peerDependencies": {
		"tedious": ">= 1.0.0"
	},
	"devDependencies": {
		"mocha": "^3.0.2",
		"simple-statistics": "^2.1.0"
	}
}

@kevinkevp
Copy link

Try with this in the config:
options.encrypt: false

Works for me, in a local MSSQL

@arthurschreiber
Copy link
Collaborator

@kevinkevp That will probably work because that will disable the TLS stream that is used for encryption purposes, greatly simplifying the internal connection handling. But it's not a proper fix, because encryption support is a hard requirement for many use cases.

I'll take https://github.com/tediousjs/tedious/compare/arthur/rework-connection-close and see if I can polish it up!

@dhollenbeck
Copy link

I am getting the same error as the @irgijs and therefore unable to update the tedious driver.

@irgijs
Copy link
Author

irgijs commented Jun 17, 2019

@arthurschreiber Are you expecting to find a solution anytime soon? Is there something we can do to help you?

@irgijs
Copy link
Author

irgijs commented Jul 26, 2019

@arthurschreiber We really want to update to the latest tedious version, but this issue prevents us from doing so. How can we help you to fix this problem?

@ErikJansenIRefact
Copy link

@arthurschreiber This open issue is blocking our way forward. We do need a more recent Tedious version but are depending on stream processing as well. You mentioned finishing https://github.com/tediousjs/tedious/compare/arthur/rework-connection-close. Can you give us an idea of when this might be expected?

@irgijs
Copy link
Author

irgijs commented Aug 22, 2019

We have identified the issue. It is caused by the connection pool, see tediousjs/tedious-connection-pool#58

@IanChokS
Copy link
Member

@irgijs @ErikJansenIRefact, since this issue looks like it's due to tedious-connection-pool, i'll close the issue here for now. If you think there's a cause due to Tedious itself related to this, feel free to re-open this issue.

@mastodon0
Copy link
Contributor

This issue is not only restricted to tedious-conection-pool

You get the same error if you use options.encrypt: true on Node v12+ with old SQL Server versions. This is caused by Node v12 requiring TLS 1.2.
There is nothing tedious could do about it, so you got 3 options:

  • install the TLS 1.2 security patch for your SQL Server
  • run node with backwards compatibility flag: node --tls-min-v1.0
  • disable encrypted communication by setting options.encrypt: false

@arthurschreiber
Copy link
Collaborator

@mastodon0 You can also specify an earlier TLS version to use just for the connection opened by tedious. See #914 (comment)

@arthurschreiber
Copy link
Collaborator

I'm wondering if we could improve the messaging around this issue, to make it clearer to users what the issue is and how this can be worked around (and what the implications of those workarounds are).

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

No branches or pull requests

7 participants