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

bug: Inconsistent current directory resolution depending on include order #1757

Merged
merged 10 commits into from
Oct 6, 2024

Conversation

pbitty
Copy link
Contributor

@pbitty pbitty commented Aug 13, 2024

It seems there's a race condition somewhere in the Reader.include() code.

I was exploring the behaviour of the includes.*.dir options and I wrote some tests. When I did this, I found there two different behaviours that it would switch between intermittently. I tried to capture what I think is the expected behaviour in the tests and when you run the tests they will pass about 50% of the time.

I found that if I force the "include loop" to not have any concurrency, the tests pass 100% of the time.

I have tried to play around with the variable assignments and mutations that happen inside include, to see if I can isolate the cause, but no luck yet. In this PR I am posting only the tests and the concurrency fix (commented out), to highlight the problem and see if anyone has any ideas as to what's causing it.

I will continue to explore it - but if anyone has any ideas, let me know.

// the tests pass, which suggests a data race as the culprit.
//
// Uncomment this to make path-resolution bug go away
// g.SetLimit(1)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Uncommenting this will stop the bug from happening.

@pbitty pbitty changed the title potential bug: Race condition in include code bug: Inconsistent current directory resolution depending on include order Sep 3, 2024
@pbitty
Copy link
Contributor Author

pbitty commented Sep 3, 2024

I've been able to narrow down the cause to the way the includes are parsed. I haven't figured out the root cause, but it seems when that having multiple includes with the same entrypoint has something to do with it.

By disabling concurrency and putting the include with an empty dir at the end of the list, the directory resolution always works.

I will keep investigating, but if anyone spots the issue in the meantime let me know.

@pbitty pbitty marked this pull request as ready for review September 6, 2024 21:10
@pbitty
Copy link
Contributor Author

pbitty commented Sep 6, 2024

@andreynering @vmaerten , I believe I have figured out the issue. The relative path resolution in HTTP nodes only works in some scenarios because it always looks "one folder up". I believe the desired result is to make all paths relative to the parent.

If the parent is a File node, it will stop at the file node. If the parent is a HTTP node, that node will have taken the value from its parent, and so on.

Does this sound right to you?

I am still familiarizing myself with the graph merging logic, so it's possible I am misunderstanding what is happening. One thing I still don't fully understand is why the ordering matters. It seems that the first include in child-taskfile2.yml dictates the dir for tasks in the remaining includes (since they all point to the same Taskfile in the graph). How this happens is not entirely clear to me, but it's the behaviour I am seeing from the outside.

@pbitty
Copy link
Contributor Author

pbitty commented Sep 10, 2024

I'm still not entirely sure what the expected behaviour is. I've posted a question about it in Discourse - will gladly move the discussion here if that's more appropriate.

@pbitty
Copy link
Contributor Author

pbitty commented Sep 10, 2024

Whoops, I did it again - I forgot to enable remote taskfile support in the tests. If no objections, I will cherry-pick the change I did in ec64761 and then resolve any merge conflicts if both PRs are to be merged.

Copy link
Member

@vmaerten vmaerten left a comment

Choose a reason for hiding this comment

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

Hey !
I finally got the time to check it
Indeed you are right, when a remote include another remote, the dir is not correct
Thanks a lot for adding test on remote task!

@vmaerten
Copy link
Member

@pd93 I'll leave this PR open for a few days before merging it, in case you want to review it.

@pd93
Copy link
Member

pd93 commented Sep 24, 2024

@vmaerten Thanks! It's at the top of my list

@andreynering
Copy link
Member

It looks good to me, so I'm merging.

Thanks @pbitty!

@andreynering andreynering merged commit a72e70b into go-task:main Oct 6, 2024
14 checks passed
andreynering added a commit that referenced this pull request Oct 6, 2024
@pbitty pbitty deleted the include_concurrency_bug branch October 28, 2024 15:24
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