Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error handling #6

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open

Error handling #6

wants to merge 4 commits into from

Conversation

PavelLinearB
Copy link
Member

@PavelLinearB PavelLinearB commented Feb 19, 2025

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

Copy link

gitstream-cm bot commented Feb 19, 2025

✨ 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