Over a million developers have joined DZone.

Spot the bug – misbehaving server

DZone's Guide to

Spot the bug – misbehaving server

Free Resource
We had a strange issue at work – we had a misbehaving server, who worked perfectly well with one client but had strange issues when several clients connected to it. The server would broadcast a message to all of its clients but only one client would receive that specific message, re-sending the message would fix the problem occasionally but it wasn’t a very consistent behavior.

I’ve managed to find the root of the issue and created a simplified version of the issue. can you spot the bug in the following code?

public class Server
public void SendPingToClients(IEnumerable<client> clients)
foreach (var client in clients)
Task.Factory.StartNew(() => Ping(client));

public void Ping(Client client)
Console.WriteLine("ping sent to client " + client.Id);

Happy coding!

Published at DZone with permission of Dror Helper, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}