fix(webkit): set strict memory threshold before conservative to avoid assertion
- commit
- 043cd76f32a4522578fdd7c88ff689b9ca11a35c
- author
- brice · · 2025-12-28 17:13 UTC
- committer
- brice · · 2025-12-29 17:28 UTC
- parent
- 3ef6fdf
- signature
- unsigned
1 file · +20 -4
M internal/infrastructure/webkit/memory_pressure.go +20 -4
| @@ -26,6 +26,10 @@ func (*MemoryPressureApplier) ApplyNetworkProcessSettings(ctx context.Context, c | |||
| 26 | 26 | return nil | |
| 27 | 27 | } | |
| 28 | 28 | ||
| 29 | + | if cfg.ConservativeThreshold > 0 && cfg.StrictThreshold <= 0 { | |
| 30 | + | log.Warn().Msg("conservative threshold set without strict threshold; skipping conservative to avoid WebKit assertion") | |
| 31 | + | } | |
| 32 | + | ||
| 29 | 33 | settings := buildMemoryPressureSettings(cfg) | |
| 30 | 34 | if settings == nil { | |
| 31 | 35 | return nil | |
| @@ -54,6 +58,10 @@ func (*MemoryPressureApplier) ApplyWebProcessSettings(ctx context.Context, cfg * | |||
| 54 | 58 | return nil, nil | |
| 55 | 59 | } | |
| 56 | 60 | ||
| 61 | + | if cfg.ConservativeThreshold > 0 && cfg.StrictThreshold <= 0 { | |
| 62 | + | log.Warn().Msg("conservative threshold set without strict threshold; skipping conservative to avoid WebKit assertion") | |
| 63 | + | } | |
| 64 | + | ||
| 57 | 65 | settings := buildMemoryPressureSettings(cfg) | |
| 58 | 66 | if settings == nil { | |
| 59 | 67 | return nil, nil | |
| @@ -88,12 +96,20 @@ func buildMemoryPressureSettings(cfg *port.MemoryPressureConfig) *webkit.MemoryP | |||
| 88 | 96 | } | |
| 89 | 97 | ||
| 90 | 98 | // Thresholds must be in (0, 1) | |
| 91 | - | if cfg.ConservativeThreshold > 0 && cfg.ConservativeThreshold < 1 { | |
| 92 | - | settings.SetConservativeThreshold(cfg.ConservativeThreshold) | |
| 99 | + | // IMPORTANT: WebKit asserts that conservative < strict, so set strict first. | |
| 100 | + | strict := cfg.StrictThreshold | |
| 101 | + | conservative := cfg.ConservativeThreshold | |
| 102 | + | ||
| 103 | + | if strict > 0 && strict < 1 { | |
| 104 | + | settings.SetStrictThreshold(strict) | |
| 93 | 105 | } | |
| 94 | 106 | ||
| 95 | - | if cfg.StrictThreshold > 0 && cfg.StrictThreshold < 1 { | |
| 96 | - | settings.SetStrictThreshold(cfg.StrictThreshold) | |
| 107 | + | // Only set conservative when we also have a strict threshold; otherwise | |
| 108 | + | // WebKit's internal default strict value may not be initialized yet. | |
| 109 | + | if conservative > 0 && conservative < 1 && strict > 0 { | |
| 110 | + | if conservative < strict { | |
| 111 | + | settings.SetConservativeThreshold(conservative) | |
| 112 | + | } | |
| 97 | 113 | } | |
| 98 | 114 | ||
| 99 | 115 | // Kill threshold: -1 = unset, 0 = never kill, >0 = threshold | |
| @@ -26,6 +26,10 @@ func (*MemoryPressureApplier) ApplyNetworkProcessSettings(ctx context.Context, c | |||||
| 26 | return nil | 26 | return nil | ||
| 27 | } | 27 | } | ||
| 28 | 28 | ||||
| 29 | + | if cfg.ConservativeThreshold > 0 && cfg.StrictThreshold <= 0 { | |||
| 30 | + | log.Warn().Msg("conservative threshold set without strict threshold; skipping conservative to avoid WebKit assertion") | |||
| 31 | + | } | |||
| 32 | + | ||||
| 29 | settings := buildMemoryPressureSettings(cfg) | 33 | settings := buildMemoryPressureSettings(cfg) | ||
| 30 | if settings == nil { | 34 | if settings == nil { | ||
| 31 | return nil | 35 | return nil | ||
| @@ -54,6 +58,10 @@ func (*MemoryPressureApplier) ApplyWebProcessSettings(ctx context.Context, cfg * | |||||
| 54 | return nil, nil | 58 | return nil, nil | ||
| 55 | } | 59 | } | ||
| 56 | 60 | ||||
| 61 | + | if cfg.ConservativeThreshold > 0 && cfg.StrictThreshold <= 0 { | |||
| 62 | + | log.Warn().Msg("conservative threshold set without strict threshold; skipping conservative to avoid WebKit assertion") | |||
| 63 | + | } | |||
| 64 | + | ||||
| 57 | settings := buildMemoryPressureSettings(cfg) | 65 | settings := buildMemoryPressureSettings(cfg) | ||
| 58 | if settings == nil { | 66 | if settings == nil { | ||
| 59 | return nil, nil | 67 | return nil, nil | ||
| @@ -88,12 +96,20 @@ func buildMemoryPressureSettings(cfg *port.MemoryPressureConfig) *webkit.MemoryP | |||||
| 88 | } | 96 | } | ||
| 89 | 97 | ||||
| 90 | // Thresholds must be in (0, 1) | 98 | // Thresholds must be in (0, 1) | ||
| 91 | - | if cfg.ConservativeThreshold > 0 && cfg.ConservativeThreshold < 1 { | 99 | + | // IMPORTANT: WebKit asserts that conservative < strict, so set strict first. |
| 92 | - | settings.SetConservativeThreshold(cfg.ConservativeThreshold) | 100 | + | strict := cfg.StrictThreshold |
| 101 | + | conservative := cfg.ConservativeThreshold | |||
| 102 | + | ||||
| 103 | + | if strict > 0 && strict < 1 { | |||
| 104 | + | settings.SetStrictThreshold(strict) | |||
| 93 | } | 105 | } | ||
| 94 | 106 | ||||
| 95 | - | if cfg.StrictThreshold > 0 && cfg.StrictThreshold < 1 { | 107 | + | // Only set conservative when we also have a strict threshold; otherwise |
| 96 | - | settings.SetStrictThreshold(cfg.StrictThreshold) | 108 | + | // WebKit's internal default strict value may not be initialized yet. |
| 109 | + | if conservative > 0 && conservative < 1 && strict > 0 { | |||
| 110 | + | if conservative < strict { | |||
| 111 | + | settings.SetConservativeThreshold(conservative) | |||
| 112 | + | } | |||
| 97 | } | 113 | } | ||
| 98 | 114 | ||||
| 99 | // Kill threshold: -1 = unset, 0 = never kill, >0 = threshold | 115 | // Kill threshold: -1 = unset, 0 = never kill, >0 = threshold | ||