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

Error in initialization of client with macOS #56

Closed
ChingEn-Lin opened this issue Apr 21, 2022 · 16 comments
Closed

Error in initialization of client with macOS #56

ChingEn-Lin opened this issue Apr 21, 2022 · 16 comments
Assignees
Labels
bug Something isn't working

Comments

@ChingEn-Lin
Copy link

ValueError: invalid literal for int() with base 10: b'2022-04-21T17:34:12.398+0200 I CONTROL [js] machdep.cpu.extfeatures unavailable\n0\n'
when trying to instantiate client with client = MongoClient()

To Reproduce

from pymongo_inmemory import MongoClient
client = MongoClient()

gives the error
ValueError: invalid literal for int() with base 10: b'2022-04-21T17:34:12.398+0200 I CONTROL [js] machdep.cpu.extfeatures unavailable\n0\n'

Logs

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "./lib/python3.7/site-packages/pymongo_inmemory/_pim.py", line 9, in __init__
    self._mongod.start()
  File "./python3.7/site-packages/pymongo_inmemory/mongod.py", line 101, in start
    while not self.is_healthy:./python3.7/site-packages/pymongo_inmemory/mongod.py", line 140, in is_healthy
    if int(uptime) > 0:
ValueError: invalid literal for int() with base 10: b'2022-04-21T17:34:12.398+0200 I CONTROL  [js] machdep.cpu.extfeatures unavailable\n0\n'

Context:

  • macOS Monterey with M1 chip
  • pytest-6.2.2
  • mongo4.2
@ChingEn-Lin ChingEn-Lin added the bug Something isn't working label Apr 21, 2022
@ekarademir
Copy link
Collaborator

Hi @ChingEn-Lin I'm going to look into this.

@ekarademir ekarademir self-assigned this Apr 22, 2022
@ekarademir
Copy link
Collaborator

Hi @ChingEn-Lin could you please post the output of

python -c "import platform; print(platform.uname())"

I don't have an M1 machine, so I need your help debugging this. The version of MongoDB is determined by the output of a similar Python function. I wonder if the output has changed for M1 chips.

@ChingEn-Lin
Copy link
Author

ChingEn-Lin commented May 1, 2022 via email

@ekarademir
Copy link
Collaborator

Hi @ChingEn-Lin

Thank you for the output. I think it's not about selecting the version, but how the code decides if MongoDB server is running or not. So the debugging will be harder. Below steps is basically what pymongo_inmemory does. The aim is to see if the commands it's using are producing the output that it's expecting. When you have time could you do the following please:

mkdir data
./mongod --storageEngine ephemeralForTest --dbpath ./data
  • Once the server is alive, then on the other terminal start the REPL
./mongo
  • Once REPL starts, on the REPL terminal, could you run this command and send on the output?
db.serverStatus().uptime
  • Once you get the output, you can exit the REPL with exit and you can stop the server with Ctrl + C.

@ChingEn-Lin
Copy link
Author

ChingEn-Lin commented May 3, 2022 via email

@ekarademir
Copy link
Collaborator

Indeed, that is the expected output. However this might be related to your particular case:
https://jira.mongodb.org/browse/SERVER-56416

Apparently MongoDB server outputs an extra line of logging with CPU features summary.

It looks like it has been fixed in 4.4.10 and 5.0.4, I'm guessing also in other minor versions. I'm going to publish a new version of pymongo_inmemory which will include option to download these versions. Could you try again after the next release?

If you are tied to this version, I will try to blindly create a patch and I might need your help testing it.

@ChingEn-Lin
Copy link
Author

ChingEn-Lin commented May 3, 2022 via email

@ekarademir
Copy link
Collaborator

I pushed a new release few ours ago. Could you try if the problem is resolved with 4.4 or 5.0?

@ChingEn-Lin
Copy link
Author

ChingEn-Lin commented May 3, 2022

I am using MongoDB shell version v5.0.7 and pymongo-inmemory version: 0.2.7, still get the same

 Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "./lib/python3.7/site-packages/pymongo_inmemory/_pim.py", line 9, in __init__
    self._mongod.start()
  File "./lib/python3.7/site-packages/pymongo_inmemory/mongod.py", line 112, in start
    while not self.is_healthy:
  File "./lib/python3.7/site-packages/pymongo_inmemory/mongod.py", line 154, in is_healthy
    if int(uptime) > 0:
ValueError: invalid literal for int() with base 10: b'2022-05-03T15:25:41.744+0200 I CONTROL  [js] machdep.cpu.extfeatures unavailable\n0\n'

for the code

@ekarademir
Copy link
Collaborator

Ok, thanks for trying out. I'll try creating a patch on a branch then I might ask you to test it. It will take me few days :)

@ekarademir ekarademir mentioned this issue May 9, 2022
@ekarademir
Copy link
Collaborator

Hi @ChingEn-Lin ,

As mentioned above, I created a fix for this issue. However now we need to see if it solves your issue.

Could you do the following please?

  1. Reproduce the issue, or, make sure the issue is still there. For this you'd need at least poetry installed on the system. Or, you can install the only runtime dependency, pymongo via pip. The choice is yours.
git clone https://github.com/kaizendorks/pymongo_inmemory.git
cd pymongo_inmemory
# Only if you have poetry
poetry install --no-root
poetry shell
# If you don't have poetry
pip install pymongo

Then,

python -m pymongo_inmemory.mongod

Or you can create the same test file you've mentioned in this PR and see if the problem is still there.

  1. Now we observed that the problem is there, we checkout the fix and run the code again, in the same repository directory
git checkout Issue56

and run the same test and see if the problem is still there.

@ChingEn-Lin
Copy link
Author

ChingEn-Lin commented May 10, 2022 via email

@ekarademir
Copy link
Collaborator

Ok. I'll create a new version anyway, because I think similar problems arose in Windows as well. After that you can update the version and see if the problem is still there.

@ekarademir
Copy link
Collaborator

Hi @ChingEn-Lin I published a new version. Could you update the version you are using and try to see if your problem is solved?

@ChingEn-Lin
Copy link
Author

Hello, the problem is solved, thank you very much!

@ekarademir
Copy link
Collaborator

Great to hear!

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