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(router): avoid settings logger from request due to race conditions #70

Merged
merged 4 commits into from
Mar 4, 2022

Conversation

Pitasi
Copy link
Contributor

@Pitasi Pitasi commented Mar 1, 2022

This fixes failing code_cov tests due to a concurrency problem that I did point out here: #20 (comment).

@gsora
Copy link
Contributor

gsora commented Mar 1, 2022

Hmm, why CI is all red? 🤔

@Pitasi
Copy link
Contributor Author

Pitasi commented Mar 1, 2022

Hmm, why CI is all red? 🤔

because it's blocked by this change: EmerisHQ/emeris-utils#37 I don't know the best practice of managing this kind of changes across multiple repositories :/

@sgerogia
Copy link
Contributor

sgerogia commented Mar 1, 2022

Hmm, why CI is all red? 🤔

because it's blocked by this change: allinbits/emeris-utils#37 I don't know the best practice of managing this kind of changes across multiple repositories :/

@antonio The allinbits/emeris-utils#37 PR needs to be marked with minor or patch label (depending on compatibility).
This will auto-generate a version, preventing accidental downstream breaks.
See for example some closed PRs

Copy link
Contributor

@0xmuralik 0xmuralik left a comment

Choose a reason for hiding this comment

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

Now that setLoggerFromContext is removed, I think we need to use the AddCorrelationIDToLogger in deps.LogError and deps.WriteError too, so that the correlation id's get included there.

@Pitasi
Copy link
Contributor Author

Pitasi commented Mar 2, 2022

Now that setLoggerFromContext is removed, I think we need to use the AddCorrelationIDToLogger in deps.LogError and deps.WriteError too, so that the correlation id's get included there.

The deps logger already contains the correlation id, right? It should be set by the CorrelationIDMiddleware you wrote.

@0xmuralik
Copy link
Contributor

Now that setLoggerFromContext is removed, I think we need to use the AddCorrelationIDToLogger in deps.LogError and deps.WriteError too, so that the correlation id's get included there.

The deps logger already contains the correlation id, right? It should be set by the CorrelationIDMiddleware you wrote.

Could run this locally and check if the logRequest and deps include correlationIds?

@Pitasi
Copy link
Contributor Author

Pitasi commented Mar 2, 2022

@SpideyPool192 I see your point. I didn't understand that the middleware was setting a logger inside the gin.context, but we weren't using it 😅

So my last commit: fc25f38 (#70) should fix that. Let me know if it seems right to you.

Eventually in my head the whole deps package will go away, since all the deps are "static" (aka not depending on the particular HTTP request, they are the same for everyone), expect for the logger (so only the logger will be treated differently). But that's for the future :)

@0xmuralik
Copy link
Contributor

0xmuralik commented Mar 3, 2022

So my last commit: fc25f38 (#70) should fix that. Let me know if it seems right to you.

We already have a logging.GetLoggerFromContext in utils. Can we refactor that if necessary and use it here?

@Pitasi Pitasi force-pushed the fix/router-race-condition branch from fc25f38 to 5327870 Compare March 3, 2022 10:25
@Pitasi
Copy link
Contributor Author

Pitasi commented Mar 3, 2022

So my last commit: fc25f38 (#70) should fix that. Let me know if it seems right to you.

We already have a logging.GetLoggerFromContext in utils. Can we refactor that if necessary and use it here?

amazing, thanks for pointing it out! I removed my method which basically was the same in favour of the utils one.

Copy link
Contributor

@0xmuralik 0xmuralik left a comment

Choose a reason for hiding this comment

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

LGTM.

@Pitasi Pitasi force-pushed the fix/router-race-condition branch from 5327870 to a69c256 Compare March 3, 2022 12:39
@Pitasi Pitasi force-pushed the fix/router-race-condition branch from a69c256 to 461aef0 Compare March 3, 2022 12:43
@Pitasi Pitasi merged commit 0929586 into main Mar 4, 2022
@Pitasi Pitasi deleted the fix/router-race-condition branch March 4, 2022 10:43
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.

4 participants