mirror of
https://github.com/saltstack/salt.git
synced 2025-04-10 14:51:40 +00:00
Filter unpicklable objects from the context dict when necessary
This commit is contained in:
parent
a27549800b
commit
fd7b0dcea2
2 changed files with 26 additions and 1 deletions
1
changelog/66999.fixed.md
Normal file
1
changelog/66999.fixed.md
Normal file
|
@ -0,0 +1 @@
|
|||
Filtered unpicklable objects from the context dict when invoking states in parallel on spawning platforms to avoid a crash
|
|
@ -18,6 +18,7 @@ import importlib
|
|||
import inspect
|
||||
import logging
|
||||
import os
|
||||
import pickle
|
||||
import random
|
||||
import re
|
||||
import site
|
||||
|
@ -2288,7 +2289,30 @@ class State:
|
|||
args=(instance, self._init_kwargs, name, cdata, low, inject_globals),
|
||||
name=f"ParallelState({name})",
|
||||
)
|
||||
proc.start()
|
||||
try:
|
||||
proc.start()
|
||||
except TypeError as err:
|
||||
# Some modules use the context to cache unpicklable objects like
|
||||
# database connections or loader instances.
|
||||
# Ensure we don't crash because of that on spawning platforms.
|
||||
if "cannot pickle" not in str(err):
|
||||
raise
|
||||
clean_context = {}
|
||||
for var, val in self._init_kwargs["context"].items():
|
||||
try:
|
||||
pickle.dumps(val)
|
||||
except TypeError:
|
||||
pass
|
||||
else:
|
||||
clean_context[var] = val
|
||||
init_kwargs = self._init_kwargs.copy()
|
||||
init_kwargs["context"] = clean_context
|
||||
proc = salt.utils.process.Process(
|
||||
target=self._call_parallel_target,
|
||||
args=(instance, init_kwargs, name, cdata, low, inject_globals),
|
||||
name=f"ParallelState({name})",
|
||||
)
|
||||
proc.start()
|
||||
ret = {
|
||||
"name": name,
|
||||
"result": None,
|
||||
|
|
Loading…
Add table
Reference in a new issue