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

Fix TCP client seeing "already connected" error when resend message after having exception in the first send #94

Merged
merged 5 commits into from
Feb 18, 2022

Conversation

caowei-amazon
Copy link

@caowei-amazon caowei-amazon commented Feb 11, 2022

Issue #, if available:
When TCP client sends a message and had exception, it will reuse the same socket to send another message which would cause error since the socket already in use.
Related ticket: https://issues.amazon.com/issues/P54323886

Description of changes:

  • Everytime when the client send message, create a new socket.
  • Added aws session token to allow accessibility for cw agent

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@caowei-amazon caowei-amazon changed the title Caowei TCP client issue Feb 11, 2022
this.endpoint = endpoint;
}

private void connect() {
try {
// Avoid "socket already connected" error (https://issues.amazon.com/issues/P54323886)
Copy link
Member

Choose a reason for hiding this comment

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

Remove the link from this comment. Also, the comment might not even be needed. If we keep it, you should be more descriptive as to why we want to create a new socket on every connect() call.

build.gradle Outdated
@@ -64,6 +64,7 @@ dependencies {
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.11.1'
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.11.1'
implementation 'org.slf4j:slf4j-api:1.7.30'
implementation 'org.slf4j:slf4j-simple:1.7.30'
Copy link
Member

Choose a reason for hiding this comment

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

This shouldn't be needed

Copy link
Author

Choose a reason for hiding this comment

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

Without this, we'd see

software.amazon.cloudwatchlogs.emf.MetricsLoggerIntegrationTest > testMultipleFlushesOverTCP STANDARD_ERROR
    SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
    SLF4J: Defaulting to no-operation (NOP) logger implementation
    SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

Copy link
Member

Choose a reason for hiding this comment

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

This is okay, we don't want or need to provide a logging implementation. User's provide their own logger.

@@ -22,6 +23,7 @@ pushd $rootdir/src/integration-test/resources/agent
echo "[AmazonCloudWatchAgent]
aws_access_key_id = $AWS_ACCESS_KEY_ID
aws_secret_access_key = $AWS_SECRET_ACCESS_KEY
aws_session_token = $AWS_SESSION_TOKEN
Copy link
Member

Choose a reason for hiding this comment

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

Can you try running integration tests with an IAM user with no session token variable set, and see if this still works?

Also, we'll want this on master later as well.

Copy link
Member

Choose a reason for hiding this comment

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

Okay cool. We still want to be using temporary credentials with a session token when possible, I just want to make sure it will still continue to work with long-lived credentials (if someone running the tests chooses to do that).

@evanuk
Copy link
Member

evanuk commented Feb 11, 2022

Can you make the PR title more descriptive please, describing more what this change is fixing/doing.

@caowei-amazon caowei-amazon changed the title TCP client issue TCP client seeing "already connected" error when resend message after having exception in the first send Feb 11, 2022
@caowei-amazon caowei-amazon changed the title TCP client seeing "already connected" error when resend message after having exception in the first send Fix TCP client seeing "already connected" error when resend message after having exception in the first send Feb 11, 2022
@giancarlokc giancarlokc self-requested a review February 18, 2022 22:17
@@ -48,4 +48,50 @@ protected Socket createSocket() {

assertEquals(bos.toString(), message);
}

@Test
public void testSendMessageWithGetOSException_THEN_createSocketTwice() throws IOException {
Copy link
Member

Choose a reason for hiding this comment

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

Once this PR is merged can we also add these tests to the master branch?

Copy link
Author

Choose a reason for hiding this comment

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

Yes. I believe this also apply to that

@caowei-amazon caowei-amazon merged commit 61649ec into emf_java_1.0 Feb 18, 2022
@caowei-amazon caowei-amazon deleted the caowei branch February 18, 2022 22:37
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

Successfully merging this pull request may close these issues.

None yet

3 participants