(photos not to scale)
Such incidents are likely to occur.
American troops are deployed in assorted sensitive areas around the world, and must be sensitive to the threat of attack.
How can accident and bloodshed be avoided? Best redeploy in the mainland USA, and slowly shrink the size of the US military -- it is too large, too widely deployed, too expensive. Posting US military forces all around the world generates trouble.
Too often US military presence relies on cozy relationships with despotic and non-democratic unpopular regimes. When we prop-up the hated government, no doubt local people despise our presence. Bring the US troops home.