fix: eliminate race condition in concurrent mode with custom font#574
fix: eliminate race condition in concurrent mode with custom font#574mimol91 wants to merge 1 commit into
Conversation
Clone font bytes before passing to gofpdf so each worker goroutine owns its backing array; gofpdf mutates the slice during GenerateCutFont via append-padding in generateChecksum, causing write/write races when the same bytes were shared across Fpdf instances.
📝 WalkthroughWalkthroughThe PR adds font byte slice cloning to the PDF builder to prevent aliasing issues during custom font registration, and introduces a concurrent test that validates the fix by repeatedly generating PDFs while using a registered TTF font under concurrent access. ChangesFont Byte Cloning and Validation
🎯 2 (Simple) | ⏱️ ~8 minutes
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Description
gofpdf mutates the slice during GenerateCutFont via append-padding in generateChecksum, causing write/write races when the same bytes are shared across Fpdf instances.
This PR fixes the issue by copying byte slice
Related Issue
Checklist
func (<first letter of struct> *struct) method() {}name style.when,shouldnaming pattern.m := mocks.NewConstructor(t).m.EXPECT().MethodName()method to mock methods.example_test.go.make dodwith none issues pointed out bygolangci-lint