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

Train releases component resource too early #55

Closed
peterlai1 opened this issue Mar 20, 2023 · 2 comments
Closed

Train releases component resource too early #55

peterlai1 opened this issue Mar 20, 2023 · 2 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@peterlai1
Copy link
Collaborator

peterlai1 commented Mar 20, 2023

In the train traversal method, the with block at line 87 will release the resource from the train once the train has finished traversing the current segment. However, in the next loop iteration, the train may not be immediately transferred to the next segment (due to an enforced arrival time, or having to wait to use the next segment). While it waits, it should still be using the previous component's resource, but in the current implementation it is not, so the previous component's resource could have a higher number of free usage slots than it should.

A simple fix would be to not use the with statement and explicitly calling resource.release() (passing in the previous req object) when the train is successfully transferred to its next segment (in the next iteration of the loop).

https://github.com/transit-analytics-lab/spur/blob/8b4eb0c45b0b5687077b18cc4024ca9a03a494b2/spur/core/train.py#L69-L121

@peterlai1 peterlai1 added the bug Something isn't working label Mar 20, 2023
@peterlai1 peterlai1 self-assigned this Mar 20, 2023
@wklumpen
Copy link
Collaborator

So the key here is to make sure that we're not losing anything by getting rid of the with in place of an explicit request/release. Otherwise the suggested fix makes sense.

@peterlai1
Copy link
Collaborator Author

Closed as completed (#61)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants