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

Change logic around closing connections and writers API-1283 #1417

Merged
merged 10 commits into from
Dec 5, 2022

Conversation

srknzl
Copy link
Member

@srknzl srknzl commented Nov 17, 2022

fixes #1256

The issue was writing some data to the connection after it being closed. I changed and refactored some logic around PipelinedWriter and Connection to avoid that.

  • Moved socket closing responsibility to Writers
  • Fixed a test in PipelinedWriterTest
  • Ongoing and future socket.write calls will end with an error after the writer is closed. This is because close() destroys the socket and any ongoing and future socket.write calls will end with an error as described in node.js documentation. So we will be able to reject all deferred promises in the write queue upon close due to connection.close() or socket write error close().
  • We were not closing the socket on write error before, now we do it. We were sending end packet and don't write anymore. This is the same as java. See

const err = new Error();
setUpWriteFailure(err);

const resolver = deferredPromise();
writer.write(createMessageFromString('test'), resolver);
resolver.promise.catch((err) => {
expect(err).to.be.equal(err);
Copy link
Member Author

@srknzl srknzl Nov 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was strange, basically making 1 === 1 assertion. It does not work if I rename one of the variables because we were wraping (and still doing) the err in IOError. (in a defected way we pass error as message, fixed that as well.)

@codecov
Copy link

codecov bot commented Nov 18, 2022

Codecov Report

Merging #1417 (96d534f) into master (2ac53b4) will decrease coverage by 0.07%.
The diff coverage is 84.61%.

@@            Coverage Diff             @@
##           master    #1417      +/-   ##
==========================================
- Coverage   93.27%   93.20%   -0.08%     
==========================================
  Files         464      466       +2     
  Lines       16386    16623     +237     
  Branches     1333     1351      +18     
==========================================
+ Hits        15284    15493     +209     
- Misses        801      827      +26     
- Partials      301      303       +2     
Impacted Files Coverage Δ
src/network/Connection.ts 94.82% <84.61%> (+0.60%) ⬆️
src/network/ConnectionManager.ts 79.81% <0.00%> (-5.17%) ⬇️
src/core/UUID.ts 85.00% <0.00%> (-5.00%) ⬇️
src/codec/SqlExecuteCodec.ts 95.74% <0.00%> (-4.26%) ⬇️
src/util/Util.ts 86.30% <0.00%> (-1.60%) ⬇️
src/protocol/ErrorFactory.ts 64.66% <0.00%> (-0.76%) ⬇️
src/core/HazelcastError.ts 77.61% <0.00%> (-0.42%) ⬇️
src/serialization/ObjectData.ts 88.93% <0.00%> (-0.40%) ⬇️
src/config/ConfigBuilder.ts 90.29% <0.00%> (-0.39%) ⬇️
src/core/index.ts 100.00% <0.00%> (ø)
... and 121 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

}
for (const item of this.queue) {
item.resolver.reject(this.error);
item.resolver.reject(error);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is added but not covered, and this is normal. Actually there was no test before my change as well. I did not change the logic of here. Just added this.close() to the end of this function. I don't want to add a test for this because it is not trivial and requires some magic with sinon.

@srknzl srknzl changed the title Fix pipelined writer API-1283 Change logic around closing connections and writers API-1283 Nov 18, 2022
src/network/Connection.ts Outdated Show resolved Hide resolved
src/network/Connection.ts Outdated Show resolved Hide resolved
mdumandag
mdumandag previously approved these changes Dec 2, 2022
@srknzl
Copy link
Member Author

srknzl commented Dec 2, 2022

Note regarding coverage: The coverage drop is shown as 0.16% but I see that the drop is due to SSL tests because the drop is in connectTLSSocket. I think it should be related to the ssl tests being disabled. (Due to certificate issue)

Also note that codecov does not show a line that is added but not covered in this PR. (except a single line, I explained it above)

Copy link
Contributor

@harunalpak harunalpak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed all codes and tests, it seems good. I could not find any problem. I have only one question that I am not sure. After response I can approve.

@srknzl srknzl merged commit 2d0b397 into hazelcast:master Dec 5, 2022
srknzl added a commit to srknzl/hazelcast-nodejs-client that referenced this pull request Dec 5, 2022
srknzl added a commit that referenced this pull request Dec 5, 2022
harunalpak pushed a commit to harunalpak/hazelcast-nodejs-client that referenced this pull request Dec 7, 2022
…st#1417)

The issue was writing some data to the connection after it being closed. I changed and refactored some logic around PipelinedWriter and Connection to avoid that. 

- Moved socket closing responsibility to Writers
- Fixed a test in PipelinedWriterTest
- Ongoing and future socket.write calls will end with an error after the writer is closed. This is because close() destroys the socket and any ongoing and future socket.write calls will end with an error as described in node.js [documentation](https://nodejs.org/api/stream.html#writabledestroyerror). So we will be able to reject all deferred promises in the write queue upon close due to connection.close() or socket write error close().
- We were not closing the socket on write error before, now we do it. We were sending end packet and don't write anymore. This is the same as java. [See](https://hazelcast.slack.com/archives/C01JU7ZJYGP/p1668695419424179)

fixes hazelcast#1256
harunalpak pushed a commit to harunalpak/hazelcast-nodejs-client that referenced this pull request Dec 7, 2022
harunalpak pushed a commit to harunalpak/hazelcast-nodejs-client that referenced this pull request Dec 8, 2022
…st#1417)

The issue was writing some data to the connection after it being closed. I changed and refactored some logic around PipelinedWriter and Connection to avoid that. 

- Moved socket closing responsibility to Writers
- Fixed a test in PipelinedWriterTest
- Ongoing and future socket.write calls will end with an error after the writer is closed. This is because close() destroys the socket and any ongoing and future socket.write calls will end with an error as described in node.js [documentation](https://nodejs.org/api/stream.html#writabledestroyerror). So we will be able to reject all deferred promises in the write queue upon close due to connection.close() or socket write error close().
- We were not closing the socket on write error before, now we do it. We were sending end packet and don't write anymore. This is the same as java. [See](https://hazelcast.slack.com/archives/C01JU7ZJYGP/p1668695419424179)

fixes hazelcast#1256
harunalpak pushed a commit to harunalpak/hazelcast-nodejs-client that referenced this pull request Dec 8, 2022
…st#1417)

The issue was writing some data to the connection after it being closed. I changed and refactored some logic around PipelinedWriter and Connection to avoid that. 

- Moved socket closing responsibility to Writers
- Fixed a test in PipelinedWriterTest
- Ongoing and future socket.write calls will end with an error after the writer is closed. This is because close() destroys the socket and any ongoing and future socket.write calls will end with an error as described in node.js [documentation](https://nodejs.org/api/stream.html#writabledestroyerror). So we will be able to reject all deferred promises in the write queue upon close due to connection.close() or socket write error close().
- We were not closing the socket on write error before, now we do it. We were sending end packet and don't write anymore. This is the same as java. [See](https://hazelcast.slack.com/archives/C01JU7ZJYGP/p1668695419424179)

fixes hazelcast#1256
harunalpak pushed a commit to harunalpak/hazelcast-nodejs-client that referenced this pull request Dec 8, 2022
harunalpak pushed a commit to harunalpak/hazelcast-nodejs-client that referenced this pull request Dec 8, 2022
harunalpak pushed a commit to harunalpak/hazelcast-nodejs-client that referenced this pull request Dec 8, 2022
…st#1417)

The issue was writing some data to the connection after it being closed. I changed and refactored some logic around PipelinedWriter and Connection to avoid that. 

- Moved socket closing responsibility to Writers
- Fixed a test in PipelinedWriterTest
- Ongoing and future socket.write calls will end with an error after the writer is closed. This is because close() destroys the socket and any ongoing and future socket.write calls will end with an error as described in node.js [documentation](https://nodejs.org/api/stream.html#writabledestroyerror). So we will be able to reject all deferred promises in the write queue upon close due to connection.close() or socket write error close().
- We were not closing the socket on write error before, now we do it. We were sending end packet and don't write anymore. This is the same as java. [See](https://hazelcast.slack.com/archives/C01JU7ZJYGP/p1668695419424179)

fixes hazelcast#1256
harunalpak pushed a commit to harunalpak/hazelcast-nodejs-client that referenced this pull request Dec 8, 2022
…st#1417)

The issue was writing some data to the connection after it being closed. I changed and refactored some logic around PipelinedWriter and Connection to avoid that. 

- Moved socket closing responsibility to Writers
- Fixed a test in PipelinedWriterTest
- Ongoing and future socket.write calls will end with an error after the writer is closed. This is because close() destroys the socket and any ongoing and future socket.write calls will end with an error as described in node.js [documentation](https://nodejs.org/api/stream.html#writabledestroyerror). So we will be able to reject all deferred promises in the write queue upon close due to connection.close() or socket write error close().
- We were not closing the socket on write error before, now we do it. We were sending end packet and don't write anymore. This is the same as java. [See](https://hazelcast.slack.com/archives/C01JU7ZJYGP/p1668695419424179)

fixes hazelcast#1256
harunalpak pushed a commit to harunalpak/hazelcast-nodejs-client that referenced this pull request Dec 8, 2022
…st#1417)

The issue was writing some data to the connection after it being closed. I changed and refactored some logic around PipelinedWriter and Connection to avoid that. 

- Moved socket closing responsibility to Writers
- Fixed a test in PipelinedWriterTest
- Ongoing and future socket.write calls will end with an error after the writer is closed. This is because close() destroys the socket and any ongoing and future socket.write calls will end with an error as described in node.js [documentation](https://nodejs.org/api/stream.html#writabledestroyerror). So we will be able to reject all deferred promises in the write queue upon close due to connection.close() or socket write error close().
- We were not closing the socket on write error before, now we do it. We were sending end packet and don't write anymore. This is the same as java. [See](https://hazelcast.slack.com/archives/C01JU7ZJYGP/p1668695419424179)

fixes hazelcast#1256
harunalpak pushed a commit to harunalpak/hazelcast-nodejs-client that referenced this pull request Dec 8, 2022
harunalpak pushed a commit to harunalpak/hazelcast-nodejs-client that referenced this pull request Dec 8, 2022
harunalpak pushed a commit to harunalpak/hazelcast-nodejs-client that referenced this pull request Dec 8, 2022
harunalpak pushed a commit to harunalpak/hazelcast-nodejs-client that referenced this pull request Dec 8, 2022
…st#1417)

The issue was writing some data to the connection after it being closed. I changed and refactored some logic around PipelinedWriter and Connection to avoid that. 

- Moved socket closing responsibility to Writers
- Fixed a test in PipelinedWriterTest
- Ongoing and future socket.write calls will end with an error after the writer is closed. This is because close() destroys the socket and any ongoing and future socket.write calls will end with an error as described in node.js [documentation](https://nodejs.org/api/stream.html#writabledestroyerror). So we will be able to reject all deferred promises in the write queue upon close due to connection.close() or socket write error close().
- We were not closing the socket on write error before, now we do it. We were sending end packet and don't write anymore. This is the same as java. [See](https://hazelcast.slack.com/archives/C01JU7ZJYGP/p1668695419424179)

fixes hazelcast#1256
harunalpak pushed a commit to harunalpak/hazelcast-nodejs-client that referenced this pull request Dec 8, 2022
srknzl added a commit to fatihozer0/hazelcast-nodejs-client that referenced this pull request Mar 24, 2023
…st#1417)

The issue was writing some data to the connection after it being closed. I changed and refactored some logic around PipelinedWriter and Connection to avoid that. 

- Moved socket closing responsibility to Writers
- Fixed a test in PipelinedWriterTest
- Ongoing and future socket.write calls will end with an error after the writer is closed. This is because close() destroys the socket and any ongoing and future socket.write calls will end with an error as described in node.js [documentation](https://nodejs.org/api/stream.html#writabledestroyerror). So we will be able to reject all deferred promises in the write queue upon close due to connection.close() or socket write error close().
- We were not closing the socket on write error before, now we do it. We were sending end packet and don't write anymore. This is the same as java. [See](https://hazelcast.slack.com/archives/C01JU7ZJYGP/p1668695419424179)

fixes hazelcast#1256
srknzl added a commit to fatihozer0/hazelcast-nodejs-client that referenced this pull request Mar 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The error: Cannot add property 0, object is not extensible
3 participants