|
13 | 13 | import os
|
14 | 14 | import platform
|
15 | 15 | import re
|
| 16 | +import tempfile |
16 | 17 | import sys
|
17 | 18 | import traceback
|
18 | 19 | from multiprocessing import freeze_support
|
|
27 | 28 | SCRIPT_FILE = os.path.abspath(__file__)
|
28 | 29 | SCRIPT_DIR = os.path.dirname(SCRIPT_FILE)
|
29 | 30 |
|
| 31 | +def is_unix_sock_path_too_long() -> bool: |
| 32 | + """Check if the unix socket_path exceeds the 104 limit (108 on Linux). |
| 33 | +
|
| 34 | + The multiprocessing module creates a socket in the TEMPDIR folder. The |
| 35 | + socket path should not exceed: |
| 36 | + - 104 bytes on macOS |
| 37 | + - 108 bytes on Linux (https://www.man7.org/linux/man-pages/man7/unix.7.html) |
| 38 | +
|
| 39 | + Returns: |
| 40 | + bool: Whether the socket path exceeds the limit. Always False on Windows. |
| 41 | + """ |
| 42 | + |
| 43 | + if os.name != "posix": |
| 44 | + return False |
| 45 | + |
| 46 | + MAX_UNIX_SOCKET_PATH = 104 |
| 47 | + # `tempfile.mktemp` is deprecated yet that's what the multiprocessing |
| 48 | + # module uses internally: https://github.com/python/cpython/blob/c4e7d245d61ac4547ecf3362b28f64fc00aa88c0/Lib/multiprocessing/connection.py#L72 |
| 49 | + # Since we are not using the resulting file, it is safe to use this |
| 50 | + # method. |
| 51 | + sock_path = tempfile.mktemp(prefix="sock-", dir=tempfile.gettempdir()) |
| 52 | + return len(sock_path.encode("utf-8")) > MAX_UNIX_SOCKET_PATH |
| 53 | + |
30 | 54 | def confirm_tag_in_repo(tag: str, repo_name: str) -> Optional[str]:
|
31 | 55 | """Confirm that a given tag exists in a git repository. This function
|
32 | 56 | assumes that the repository is already a current working directory before
|
@@ -771,6 +795,13 @@ def main():
|
771 | 795 | "specify --scheme=foo")
|
772 | 796 | sys.exit(1)
|
773 | 797 |
|
| 798 | + if is_unix_sock_path_too_long(): |
| 799 | + print( |
| 800 | + f"TEMPDIR={tempfile.gettempdir()} is too long and multiprocessing " |
| 801 | + "sockets will exceed the size limit. Falling back to verbose mode." |
| 802 | + ) |
| 803 | + args.verbose = True |
| 804 | + |
774 | 805 | clone = args.clone
|
775 | 806 | clone_with_ssh = args.clone_with_ssh
|
776 | 807 | skip_history = args.skip_history
|
|
0 commit comments