There can be an another issue, if you're extremely unlucky
FB13701209
In short, if there are approximately 30 seconds between codesign calls, this could cause race in a timestamp service.
If codesign will be called After ~29.9 seonds of The Timestamp service will lmar conneciton as initiated, Will perform some work, and after 0.1 second will receive socked_closed
Timestamp service will treat this as unexpected connection termination, and will reply to the codesign with somewhat error.
Codesign will fail, and the build will as well.
Woekarounds:
call 'fake' codesigns
manually terminate XPCTimeStampingService between build phases that won't require codesigning for a long time (30 sec)
You can try to find what's going on with
sudo log collect --start *** and search for codesign, and / or XPCTimeStampingService calls