Image copyright Dan Kitwood

President Trump has unleashed another Twitter storm, infuriating officials in London. This has posed special challenges for the US-UK relationship.

Trump hurled an insult at London's mayor, Sadiq Khan, shortly after the terrorist attacks in his city. Then Trump went after Khan again on Monday, tweeting that he was offering only a "pathetic excuse" for the mayor's earlier statement that Britons should remain calm in the wake of the terror attack.

Many British officials are enraged - especially those who work in counterterrorism. Still there's little chance that they'll break up with the Americans. For both sides, there's too much at stake.

The relationship has had its ups and downs under the Trump administration. At certain times, the president and his aides have shown their commitment to the relationship - and said that they want things to work.

They've shown their concern in different ways.

Latest updates: London attack

Standing outside Nato's new building in Brussels last month, Sean Spicer, the White House press secretary, scrolled impatiently though his phone, looking for my email address. He wanted to send a message, and he was in a hurry. Tapping on the keypad, he told me: "It's from the president."

It was a presidential statement that condemned leaks in the US media and the way that news outlets had revealed details about a terrorism investigation in Manchester. The UK investigators were angry about the leaks and said that they didn't want to share any more information with the Americans: the Britons didn't want their secrets revealed.

The issue of the leaks had reached the highest level of government: UK Prime Minister Theresa May had even complained publicly about them.

In the president's statement, the one Spicer emailed to me in Brussels, Trump said he found the leaks in the US media "deeply troubling". He also talked about the value that he placed on the partnership between the US and the UK.

"There is no relationship we cherish more than the Special Relationship between the United States and the United Kingdom," he said. The president and his aides seemed to care deeply what Britons thought and wanted the BBC to get their message across - at least on that day.

Things changed.

On Saturday night three men drove across London Bridge in a van, slamming into pedestrians, then got out and stabbed others. The attack left seven dead and scores wounded, and afterwards European leaders expressed condolences and solidarity through postings on social media.

In contrast Trump tweeted, and then headed for a golf course.

Image copyright Carl Court/Getty Images Image caption Sadiq Khan was said to be too busy to respond to Mr Trump's tweets

Khan didn't bother to reply.

It was an unusual deep rift between officials in the US and the UK. In the realm of counterterrorism, as well as in other realms, officials from the two countries have close ties.

Trump renews feud with London Mayor

Americans who work in the intelligence community in Washington sometimes joke that Britons have easier access to one of their agencies, the Central Intelligence Agency, than they do. The Americans are exaggerating, but it's true that the Americans at the CIA and their counterparts in the UK have traditionally worked together closely on terrorism cases, attempting to track information about commanders and unravel plots before they are carried out.

The US services have vast resources for intelligence gathering and, as Chatham House's Simon Palombi pointed out, they've established a network of informants who report on activities within the al-Qaeda network and the so-called Islamic State group.

Meanwhile the British officials "have front-line experience", said Paul Pillar, a former CIA analyst and the author of a book entitled Why America Misunderstands the World, referring to the attacks that have been carried out in their country. Working together, the British and US officials are better able to understand the militants and their organisations.

They also express solidarity when things are difficult. Those who've worked in the intelligence services said that searching for clues in the hours after a terrorist attack is a challenge - and that leaders can help calm people down or rile them up.

The president's jab at the London mayor, they said, made things worse.

Image copyright Getty Images Image caption Sadiq Khan told Londoners not to be alarmed by increased police presence in the days after the attack

"It was just outrageous," said Pillar.

Pillar said: "If I were a senior official in British intelligence, my blood pressure would still be high enough to say: 'If we've done any temporary shutting off of sharing, let's just keep it shut off for now.'"

Later on Sunday the president softened his tone towards the Britons. Speaking at a Washington theatre, he said he and other Americans would "do everything in our power to assist the United Kingdom and its citizens as they work to protect their country".

His remarks underscored the importance of the relationship between the two countries. They also captured a trend in his presidential style: he antagonises other nations and people and then acts friendly. While in Brussels, Spicer had rushed out a conciliatory message from the president, and later the president acted in a less accommodating manner.

Veterans of the intelligence world understand the importance of sharing between the US and the UK, however, and say the strengths of each nation improves the overall quality of their work.

If the two nations broke up, the quality of their work would deteriorate, said Matthew Olsen, a former director of the US national counterterrorism centre. "A lot goes back and forth," he said. "Both countries would suffer."

For that reason, Pillar said, he's not worried about a breakup. He believes their relationship - like all relationships - has its ups and downs but will endure. After some time has passed since "the last insulting tweet from Donald Trump", as he put it, "they'll quietly restore relations".

"I'm not sure when that will happen," Pillar said. "But it will."