I have struggled with a similar problem. I like to make my world surround and give distinctive characteristics to all the NPCs that my group is with. However, this can cause players to talk to an NPC for 10 minutes to buy a meal.
While everyone has fun, this is not a problem. However, as noted, some players may get bored of extended dialogue. So, what I tend to do is role play the first encounter with an NPC. Give the tavern keeper a personality when they first enter. However, once the character is established, I will not play the scene unless the players try to do something interesting with the conversation. Instead, I simply state "you're going to buy a bar food, she charges you 3 cp."
If the conversation is going to be mundane, do not bother playing it completely. Keep your dialogue deep and scenes extended for important things. This has the added advantage of reducing the amount of different characters you need to play / remember.
If a conversation starts important and you want to play it on the table, you can still use some similar techniques.
Halfway through the conversation, if the PCs have collected all the important information from the NPC, tell them:
"You spend another 15 minutes talking to the sailor, but you do not learn anything more interesting, except that he has a tattoo of a mermaid in a place that will not show you."
When talking to a powerful NPC, a Lord or a ruler of some kind, you can say things like:
"The king is visibly frustrated by your continuous questions, you recognize that you only have one or two more before he tells you to leave"
If you do not notice the hint, or if this is too aggressive, remember that the NPCs are also people and probably have other things to do.
"I'm afraid I have to go, never enough hours in the day for all the things I have to do"
Then have the NPC simply leave.
You also have the option of being interrupted by another NPC. If the NPC owns a store, they will have other customers, the farmers will have children or friends, even the guard could come forward to accuse them of loitering.
What happens when the NPC has no reason to end the conversation?
Sometimes you will find yourself in a situation where none of the previous techniques will be logical. The hermit in the swamp who has no more time to talk to the adventurers, for example. In these situations, you can adopt the opposite approach, make the characters finish themselves.
PC: "How long have you been here?"
Hermit: "Well, I arrived for the first time on a full moon night … the marsh was beautiful …"
DM: The Hermit launches a 20 minute description of his arrival in the swamp.
PC: "But how long ago?"
Hermit: the same story begins …
With this approach you need to clarify the passage of time. PCs are burning daylight talking to the NPC. This means they may not have time to get to that important MacGuffin tonight.
How to know when to make the hand.
You mentioned in a comment about another answer that this was something I was struggling with, I will try to give you some advice.
From the point of view of GM, it is quite easy, if the party has compiled all the information that it intends to give them, then it is safe to do it manually. Although you must be careful not to interrupt the entertaining conversations and in which the entire table is inverted.
For example, I had a very Australian NPC (I'm also Australian and I slipped with my accent when I introduced the NPC) that the party thought was very funny. Their main objective was to give them directions to the important location of the city. However, I let the players keep talking to him until I ran out of Australian jokes, when I left him to go back to work.
The hardest part is when you know there is still information to gather, but the players have begun to review the conversation. It is difficult to give advice for this, as it will vary from one group to another, but there are some things you should keep in mind: players who recline in their chair, players who do not join the conversation, phones or other distractions that are observed, and a reduction in the role play effort.
At this point, you can reduce the conversation to a roll of dice. Ask them to conduct a social check and base the DC on how well the conversation has gone. If successful, give them all the important information in the Handwaved summary. In case of failure, they can only obtain something or even none of that.
You want to use Fiat GM and handwaving to indicate that the conversation continued but that you had all the important information. The player must trust that he has given everything he could have achieved through continuous conversation.