Problem: Pterodactyl game eggs occasionally have the below problem
The setFields() method in /app/models/services.php doesn't handle duplicate field keys in the input array. When modules or package configurations pass duplicate service fields (same key), the method attempts to insert multiple records with the same service_id + key combination, causing a primary key constraint violation:
Root Cause:
In line ~4165, the method loops through $vars and calls addField() for each entry without checking for duplicate keys. If $vars contains multiple entries with the same key, multiple INSERT statements are executed for the same service_id + key, violating the primary key constraint.
Solution:
Add deduplication logic before processing the fields array. Here's the diff that fixed the problem and stopped white redirect pages from occurring:
Benefits of this fix:
1. Prevents crashes: Eliminates primary key constraint violations
2. Maintains functionality: If duplicates exist, keeps the last occurrence (allows intentional overriding)
3. Backward compatible: No API changes, same input/output behavior
4. Future-proof: Protects against any module/package that might pass duplicate fields
Affected scenarios:
• Custom modules that generate duplicate service fields
• Package configurations with conflicting field definitions
• Third-party integrations (like Pterodactyl) with complex field mappings