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 message by program name too big #620

Closed
mrlucasrib opened this issue Oct 4, 2021 · 1 comment · Fixed by #681
Closed

Error message by program name too big #620

mrlucasrib opened this issue Oct 4, 2021 · 1 comment · Fixed by #681
Labels
Milestone

Comments

@mrlucasrib
Copy link

I'm running a python script that has a very large path, sys.argv[0] = /home/myuser/.cache/bazel/_bazel_myuser/86d86849c94045e321482e95af59d89a/execroot/mymonorepo/bazel-out/k8-fastbuild/bin/src/applications/myapp/myapp.runfiles/mymonorepo/src/applications/myapp/src/server.py. This is because the application uses bazel as a monorepo manager.
But this causes aiomysql to fail to run :

  File "/home/myuser/.cache/bazel/_bazel_myuser/86d86849c94045e321482e95af59d89a/execroot/mymonorepo/bazel-out/k8-fastbuild/bin/src/applications/myapp/myapp.runfiles/deps_python/pypi__aiomysql/aiomysql/connection.py", line 782, in _request_authentication
    data += struct.pack('B', len(connect_attrs)) + connect_attrs
struct.error: ubyte format requires 0 <= number <= 255
...
    raise OperationalError(2003,
pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on '10.5.3.133'")

This happens because it tries to create a packet to be sent over the network with 256 bytes, but the big name of the program overflows that size.

if program_name:
self._connect_attrs["program_name"] = program_name
elif sys.argv:
self._connect_attrs["program_name"] = sys.argv[0]

for k, v in self._connect_attrs.items():
k, v = k.encode('utf8'), v.encode('utf8')
connect_attrs += struct.pack('B', len(k)) + k
connect_attrs += struct.pack('B', len(v)) + v
data += struct.pack('B', len(connect_attrs)) + connect_attrs

The simplest solution would be to remove the path (or part of it) from the network packet. However, I don't know if this can cause any unexpected problems. As far as I've tested, it didn't cause any errors

I wonder if I can make a Pull Request that fixes this, leaving only the path after the last slash. Ex: from /home/myuser/.cache/bazel/_bazel_myuser/86d86849c94045e321482e95af59d89a/execroot/mymonorepo/bazel-out/k8-fastbuild/bin/src/applications/myapp/myapp.runfiles/mymonorepo/src/applications/myapp/src/server.py to server.py. This would solve my problem and that of some other people I saw while researching this error.

@Nothing4You Nothing4You linked a pull request Jan 12, 2022 that will close this issue
4 tasks
@Nothing4You
Copy link
Collaborator

As a workaround you can already pass a custom name using the program_name argument on aiomysql.create_pool and aiomysql.connect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants