Skip to content

Error handling - #6

Open
PavelLinearB wants to merge 4 commits into
developfrom
error-handling
Open

PavelLinearB wants to merge 4 commits into
developfrom
error-handling

Conversation

@PavelLinearB

@PavelLinearB PavelLinearB commented Feb 19, 2025

Copy link
Copy Markdown
Contributor

workerB

✨ PR Description

Purpose: Implements a basic client-server chat system using socket programming in Python.

Main changes:

  • Created server.py with multi-threaded connection handling and message broadcasting functionality
  • Implemented client.py with socket connection and concurrent message sending/receiving capabilities
  • Added chunked data transfer support for handling large messages up to 4096 bytes

This description was generated by LinearB AI and Added by gitStream

@gitstream-cm

gitstream-cm Bot commented Feb 19, 2025

Copy link
Copy Markdown

✨ PR Review Suggestion

Race Condition - src/server/server.py (Lines 37-40)

Details:

Problem: Unsynchronized access to shared connections list between threads could cause race conditions
Fix: Add a thread-safe lock around connections list modifications
Why: Multiple threads accessing/modifying the list simultaneously could cause data corruption or crashes

+_connections_lock = threading.Lock()

            except (socket.error, ConnectionResetError) as e:
                print("Client " + str(self.address) + " has disconnected")
                self.signal = False
+                with _connections_lock:
                    connections.remove(self)
                break

Race Condition - src/server/server.py (Lines 54-56)

Details:

Problem: Unsynchronized access to shared connections list in newConnections function
Fix: Add thread-safe lock around connections list append
Why: Multiple threads adding to the list simultaneously could cause data corruption

        sock, address = socket.accept()
        global total_connections
+        with _connections_lock:
            connections.append(Client(sock, address, total_connections, "Name", True))
            connections[len(connections) - 1].start()
            print("New connection at ID " + str(connections[len(connections) - 1]))

This review was generated by LinearB AI and Added by gitStream

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant