Skip to content

CT 1440 Fix code to emit ConnectionReused event#6605

Merged
gshank merged 5 commits intomainfrom
ct-1440-connection_reused
Jan 17, 2023
Merged

CT 1440 Fix code to emit ConnectionReused event#6605
gshank merged 5 commits intomainfrom
ct-1440-connection_reused

Conversation

@gshank
Copy link
Contributor

@gshank gshank commented Jan 13, 2023

resolves #6168

Description

The code in the adapter "set_connection_name" method was not correctly emitting a ConnectionReused event. Refactor code to make it more understandable and emit the right logging event.

Checklist

@gshank gshank requested review from a team as code owners January 13, 2023 18:28
@cla-bot cla-bot bot added the cla:yes label Jan 13, 2023
@gshank gshank requested a review from peterallenwebb January 13, 2023 18:29
Copy link
Contributor

@JCZuurmond JCZuurmond left a comment

Choose a reason for hiding this comment

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

Hi @gshank, thanks for cleaning up this code and fixing the reused connection message. I added some comments.

Creates a connection for this thread if one doesn't already
exist, and will rename an existing connection."""

conn_name: str = "master" if name is None else name
Copy link
Contributor

Choose a reason for hiding this comment

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

Type hint should be : str | None or : Optional[str]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It can't be Optional[str] because the logging events are defined in protobufs which don't have Optional[str].

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah I misread it!

# Get a connection for this thread
conn = self.get_if_exists()

if conn and conn.name == conn_name and conn.state == "open":
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we only consider a connection to be reused if the name changed? Reading the code I would expect this to also be a connection reused.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's currently not considered reused. Of course the code is so strangely factored that it's a bit hard to tell how it ought to be used.

if conn.state != "open":
conn.handle = LazyHandle(self.open)
if conn.name != conn_name:
orig_conn_name: str = conn.name or ""
Copy link
Contributor

Choose a reason for hiding this comment

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

Why switch to an empty string here? I would expect the same type being used everywhere either str | None or str

Copy link
Contributor

Choose a reason for hiding this comment

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

I misread the type above

@gshank gshank force-pushed the ct-1440-connection_reused branch from f74d9bf to ef36c91 Compare January 17, 2023 17:02
@gshank gshank merged commit 89d111a into main Jan 17, 2023
@gshank gshank deleted the ct-1440-connection_reused branch January 17, 2023 18:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[CT-1440] [Bug] Connection reused event is not shown

3 participants