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(core): fix for Windows platform #681

Merged
merged 2 commits into from
Jan 19, 2024
Merged

Conversation

StephenSorriaux
Copy link
Member

@StephenSorriaux StephenSorriaux commented Nov 4, 2022

Fixes #679

Why is this needed?

This fixes an issue with the Windows platform that appeared in the latest 2.9.0 release. This also adds a very basic testing for the Windows platform (only 1 job, for the latest version of Python and the latest version of ZK).

Proposed Changes

  • remove the os.fstat(fd) check that is invalid on Windows platform
  • adjust test_selector_select test
  • add a single job to test Windows platform (gevent seems broken on Windows so... skipped it): only 1 job because I don't feel like we need to re-test every version of Python/ZK for Windows

Does this PR introduce any breaking change?

Nah.

@StephenSorriaux StephenSorriaux force-pushed the feat/windows-testing branch 15 times, most recently from 0495776 to c901aaa Compare November 11, 2022 04:13
# XXX: needed?
# selectors_module.register handle fileobject, do we need the use of fileobj_to_fd()?
# is this test valid for Windows?
# os.fstat(fd)
Copy link
Member Author

Choose a reason for hiding this comment

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

Hello @JetDrag,

Sorry to summon you here. This os.fstat(fd) call is generating crashes on Windows because the handle is, it seems, invalid. With this call commented out, the crash does not appear (and tests are running fine).
Since you did this implementation, I was wondering if:

  • there was a reason using the fileobj_to_fd() method instead of directly giving the fileobj to selectors_module.register() (which seems to be capable of handling fileobj directly)?
  • you know if the os.fstat(fd) test is valid for Windows?

Thank you.

Copy link
Contributor

Choose a reason for hiding this comment

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

I second this.
This os.fstat() does not do anything.
Actually, python3 handles os.stat() on FD or file just fine.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

@JetDrag JetDrag Nov 15, 2022

Choose a reason for hiding this comment

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

Hi, @StephenSorriaux @ceache

The function fileobj_to_fd is same as _fileobj_to_fd function in selectors module almost except the last second line os.fstat(fd).

I did this implementation to simulate the raw select behavior via test case test_selectors_select, which is modified from Python official test cast test_select.

If I don't do that, the test cast test_errno in the test_selectors_select will fail, because the exception (OSError with errno 22, EINVAL) raise by some selectors.BaseSelector implementations don't meet the test case requirement:raise OSError with errno 9 (EBADF) when select meet a closed fd.

Maybe we cloud make some other simulate implementation to make those spec working on the Windows?

Copy link
Contributor

Choose a reason for hiding this comment

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

https://github.com/python/cpython/blob/main/Lib/test/test_select.py#L32 test_errno() for reference.

I do not think we care about this behavior in Kazoo.
Actually, the err conditions with selector when selecting "bad file descriptors" are varied depending on platform and selector implementations (there are threads about this on the Python bug report).
This is here trying to make sure that selectors implementations are all equivalente to select() behavior and we really can't do that.

IMHO. the only thing we need to do is ensure how Kazoo reacts to a closed FD.
In other words, be it EINVAL or EBADF or other, we should raise an uniform Kazoo error (with Python3, we could pass up the original, OS/Implementation dependent Exception).

What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

It maybe the best solution.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you both for your thoughts. As suggested, I tried to unify the exceptions that can be raised and catch that in the test_errno() testcase. That may be too naive, not sure really, so I would love your feedback on this.

@ceache
Copy link
Contributor

ceache commented Nov 16, 2022

@StephenSorriaux is this a draft or ready for review yet?

@StephenSorriaux StephenSorriaux marked this pull request as draft November 16, 2022 23:12
@StephenSorriaux
Copy link
Member Author

@ceache Not really, it is still a draft. I'm just too used to gitlab, which auto marks a PR as draft if "draft" is in the title.

@jeffwidman
Copy link
Member

What's needed to move this forward? It'd be nice to get this resolved for our Windows users.

@StephenSorriaux
Copy link
Member Author

I was waiting for feedbacks from @JetDrag / @ceache but I will go ahead and just finish it so that it can be reviewed.

@StephenSorriaux StephenSorriaux force-pushed the feat/windows-testing branch 2 times, most recently from 3ff9d53 to 8c747d4 Compare April 24, 2023 18:21
ceache
ceache previously approved these changes May 24, 2023
Copy link
Contributor

@ceache ceache left a comment

Choose a reason for hiding this comment

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

Thanks!

jeffwidman
jeffwidman previously approved these changes May 24, 2023
Copy link
Member

@jeffwidman jeffwidman left a comment

Choose a reason for hiding this comment

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

Looks fine to me, with the caveat that I haven't actually written/run python on 🪟 in years.

.github/workflows/testing.yml Outdated Show resolved Hide resolved
.github/workflows/testing.yml Outdated Show resolved Hide resolved
.github/workflows/testing.yml Show resolved Hide resolved
.github/workflows/testing.yml Outdated Show resolved Hide resolved
.github/workflows/testing.yml Show resolved Hide resolved
kazoo/handlers/utils.py Show resolved Hide resolved
@JetDrag
Copy link
Contributor

JetDrag commented May 25, 2023

Excellent work! @StephenSorriaux

Performing an `os.stat(fd)` on Windows platform generate a crash because the "handler is not valid". `select` already handle this possible case and there is no actual need to perform any kind of check before. This was removed, and the linked test slightly changed.
@StephenSorriaux
Copy link
Member Author

@ceache @jeffwidman Sorry to resurrect this only now, would appreciate another review if possible and finally merge this.

Copy link
Member

@jeffwidman jeffwidman left a comment

Choose a reason for hiding this comment

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

LGTM, with the caveat that I don't run Windows. But I think the additional confidence of the basic sanity test is enough to be comfortable merging this.

Thank you for your hard work on this!

@StephenSorriaux
Copy link
Member Author

Thanks for always being around my dear Jeff!

@StephenSorriaux StephenSorriaux merged commit 31fdca6 into master Jan 19, 2024
26 checks passed
@StephenSorriaux StephenSorriaux deleted the feat/windows-testing branch January 19, 2024 21:23
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.

Kazoo 2.9.0 throws "Connection dropped: socket connection error: The handle is invalid"
5 participants