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

Add context handling to coosyncconf gather #383

Closed
wants to merge 1 commit into from

Conversation

balanza
Copy link
Member

@balanza balanza commented Jan 24, 2025

Following #376

In addition, two helper functions are added to deal with channel and file reads

@balanza balanza requested review from CDimonaco and arbulu89 and removed request for CDimonaco January 24, 2025 12:00
@balanza balanza force-pushed the corosyncconf-context branch 2 times, most recently from 56ef014 to c9f3bd2 Compare January 24, 2025 13:48
@balanza balanza requested a review from janvhs January 24, 2025 13:49
@balanza balanza force-pushed the corosyncconf-context branch from c9f3bd2 to 24fb176 Compare January 24, 2025 16:37
Copy link
Contributor

@arbulu89 arbulu89 left a comment

Choose a reason for hiding this comment

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

Hey @balanza
I will play the devils advocate.
Which are the chances and consequences in time to get a cancellation request during this files reading? (considering the file might be around 50 lines).
Even if you catch that exact same point, how long this would block the cancellation?
Let's not forget that the propagation of the context is mostly to avoid a blocked state during on this, more than error reporting (if we are going to cancel, we don't care that much about the error).

In the commands and other operations had more sense, as we can have long going command executions, but reading files, which most of the cases are small.

I have the feeling that this is as overcomplicated solution for a problem we don't have.
What do you think?


for fileScanner.Scan() {
fileLines = append(fileLines, fileScanner.Text())
if ctx.Err() != nil {
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 need to check this?
I mean, utils.ScanFileContextis already returning an error in this case.
I wouldn't worry to check this thinking that between the scan file and this small piece of code we could have the cancellation.
If we are going to do so in all the gatherers (I think it is an overkill) I think we should do it in the gathering.go code.
There we already have a switch after running the Gather, so we could check there.
The purpose of thie context is to not block rather than notifying an error

@@ -212,7 +212,7 @@ func (suite *CorosyncConfTestSuite) TestCorosyncConfFileNotExists() {
factsGathered, err := c.Gather(context.Background(), factsRequest)

expectedError := &entities.FactGatheringError{
Message: "error reading corosync.conf file: could not open corosync.conf file: " +
Message: "error reading corosync.conf file: could not open not_found: " +
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: Just with this output, it looks like we are not piping properly the error messages

errChan := make(chan error, 1)
contentChan := make(chan []string)

go func() {
Copy link
Contributor

@arbulu89 arbulu89 Jan 27, 2025

Choose a reason for hiding this comment

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

question: Why do we need a thread here?
Having the for and select in the main thread is not enough?
At the end, you are staring the thread and waiting right away blocking the function. Why not simply return from the function with the error?
Or If you need to break the for loop you could add a simple variable that is set to true when the context is done

@balanza
Copy link
Member Author

balanza commented Jan 27, 2025

@arbulu89 I have the same feeling. I made the PR also to raise any concerns about whether it's needed or not.

I think we can get rid of the code and keep the test, to ensure the interfaces are confirmed. What do you think?

@arbulu89
Copy link
Contributor

@arbulu89 I have the same feeling. I made the PR also to raise any concerns about whether it's needed or not.

I think we can get rid of the code and keep the test, to ensure the interfaces are confirmed. What do you think?

I'm fine with that.
If we reuse a lot this file scanning, I'm not against having a utils function (even with the context cancelling), but I think we could have it without new threads or channels, just returning from the function when the ctx.Done() is done with the error.

@balanza balanza closed this Jan 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants