Repository: dask/distributed

Issue:
msgpack 1.0.6 breaks Client.profile on Windows
These two tests have been failing on Windows since msgpack 1.0.6 was released on conda:
```
  File "C:\Miniconda3\envs\dask-distributed\lib\site-packages\msgpack\fallback.py", line 805, in _pack
    return self._pack_map_pairs(len(obj), obj.items(), nest_limit - 1)
  File "C:\Miniconda3\envs\dask-distributed\lib\site-packages\msgpack\fallback.py", line 909, in _pack_map_pairs
    self._pack(v, nest_limit - 1)
  File "C:\Miniconda3\envs\dask-distributed\lib\site-packages\msgpack\fallback.py", line 805, in _pack
    return self._pack_map_pairs(len(obj), obj.items(), nest_limit - 1)
  File "C:\Miniconda3\envs\dask-distributed\lib\site-packages\msgpack\fallback.py", line 908, in _pack_map_pairs
    self._pack(k, nest_limit - 1)
  File "C:\Miniconda3\envs\dask-distributed\lib\site-packages\msgpack\fallback.py", line 713, in _pack
    raise ValueError("recursion limit exceeded")
ValueError: recursion limit exceeded
```

![image](https://github.com/dask/distributed/assets/6213168/35313b12-176d-439f-94fc-51cb2f2be50b)
![image](https://github.com/dask/distributed/assets/6213168/ea747644-15ba-4726-9419-335cc50bb3b1)



Discussion:
- XREF https://github.com/dask/distributed/pull/3455
The issue with `test_profile_nested_sizeof` is that
- sizeof() raises RecursionError on all platforms at 430 nested calls
- msgpack.dumps() 1.0.5 raises ValueError on all platforms at 512 nested calls
- msgpack.dumps() 1.0.6 raises ValueError on Windows at 256 nested calls and at 512 nested calls on MacOSX and Linux

`test_profile_nested_sizeof` was hitting a sweet spot where msgpack was still working but sizeof wasn't.
`test_profile_server` is more serious - this is not just a test problem. It shows that msgpack 1.0.6 simply does not have enough recursion depth on Windows to work together with profile.
```python
import sys
import msgpack

for i in range(200, 5000):
    root = outer = {}
    inner = {}

    for _ in range(i):
        outer["children"] = inner
        outer, inner = inner, {}

    try:
        msgpack.dumps(root)
    except ValueError:
        print(
            f"msgpack {msgpack.__version__} on Python "
            f"{sys.version.split()[0]}/{sys.platform} raises at {i}"
        )
        break
```
Output:
```
msgpack 1.0.5 on Python 3.9.18/linux raises at 512
msgpack 1.0.5 on Python 3.10.12/linux raises at 512
msgpack 1.0.5 on Python 3.11.5/linux raises at 512

msgpack 1.0.5 on Python 3.9.18/win32 raises at 512
msgpack 1.0.5 on Python 3.10.12/win32 raises at 512
msgpack 1.0.5 on Python 3.11.5/win32 raises at 512

msgpack 1.0.6 on Python 3.9.18/linux raises at 512
msgpack 1.0.6 on Python 3.10.12/linux raises at 512
msgpack 1.0.6 on Python 3.11.5/linux raises at 512

msgpack 1.0.6 on Python 3.9.18/win32 raises at 256
msgpack 1.0.6 on Python 3.10.12/win32 raises at 256
msgpack 1.0.6 on Python 3.11.5/win32 raises at 256
```
Upstream: https://github.com/msgpack/msgpack-python/issues/566

Resolving patch:
diff --git a/distributed/profile.py b/distributed/profile.py
--- a/distributed/profile.py
+++ b/distributed/profile.py
@@ -178,7 +178,7 @@ def process(
         # sometimes need to be recursed into as well, e.g. for serialization
         # which can cause recursion errors later on since this can generate
         # deeply nested dictionaries
-        depth = min(250, sys.getrecursionlimit() // 4)
+        depth = min(100, sys.getrecursionlimit() // 4)
 
     if any(frame.f_code.co_filename.endswith(o) for o in omit):
         return None


Test patch: