There's a great William Tenn Cold War short story about this about a race to the moon ahead of the enemy. Spoiler: the Army's crash mission reaches the moon only to discover that indeed, they weren't the first; the enemy already had a base. Who was the enemy? The Navy.
The price paid is immense.
Norbert Wiener, following WWII, noted that the secure classified treatment of military R&D proved a bigger impediment for the Allies than its enemies. There were multiple independent efforts investigating the same or similar technologies who didn't know of one another and could not share experiences. At the same time, much of the information either leaked out or was available to Axis forces (or Soviets), though development lead-time made this a fairly minor concern.
J. Robert Oppenheimer had similar observations over the Manhattan Project, and there's a famous anecdote by Richard Feynman of travelling to Oak Ridge, where uranium processing and enrichment was occurring, and realising that plant practices were at severe risk of resulting in critical masses of refined material. That wouldn't have vapourised the plant, but could have resulted in deaths, meltdowns, and extensive radioactive contamination. Feynman had to fight to make this information available to plant management and workers, so that the US wouldn't unintentionally sabotage its own efforts.