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

Memory Usage and thread count Increases Indefinitely with Simple TCP Server Code #203

Open
GeorgeFlorian opened this issue Nov 27, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@GeorgeFlorian
Copy link

Description

Even the simplest code using react-native-tcp-socket causes increasing memory usage over time. The issue occurs with a basic TCP server that accepts connections, responds with an echo, and closes the socket immediately after responding. Despite not handling or processing any data, the server continuously increases memory usage indefinitely until Android OS kills the process and the app closes with no crash or log.

Steps to reproduce

Steps to reproduce the behavior:

  1. Create a simple TCP server using react-native-tcp-socket that listens for client connections.
  2. Have the server respond with an echo message and immediately close the connection.
  3. Observe increasing memory usage over time, even with no data being processed.

Or code:

import React, { useEffect } from 'react';
import { View, Text } from 'react-native';
import TcpSocket from 'react-native-tcp-socket';

const TcpServer = () => {
useEffect(() => {
const server = TcpSocket.createServer(function (socket) {
console.log('Client connected:', socket.address());

  socket.on('data', () => {
    console.log('Received data, but ignoring it.');
    socket.write('Echo server: I got your data');
    socket.end(); // Close connection immediately
  });

  socket.on('error', (error) => {
    console.log('An error occurred with client socket:', error);
    socket.destroy();
  });

  socket.on('close', () => {
    console.log('Closed connection with', socket.address());
  });
});

server.listen({ port: 3000, host: '0.0.0.0', reuseAddress: true }, () => {
  console.log('Server is listening on port 3000');
});

return () => {
  server.close(() => {
    console.log('Server has been closed');
  });
};

}, []);

return (
<View>
<Text>TCP Server is running...</Text>
</View>
);
};

export default TcpServer;

Current behavior

Even with this minimal code, memory usage increases indefinitely as the server keeps accepting and closing connections, without processing or handling the data. The server does not leak data but causes increasing memory consumption due to uncleaned resources or improper socket handling.

Expected behavior

Memory usage should remain stable, even when handling multiple connections in such a simple use case. The server should close connections properly and free resources after responding to clients, with no noticeable increase in memory consumption over time.

Relevant information

   
OS Android 12
react-native 0.74.5
react-native-tcp-socket 6.2.0
Device Physical Device
@GeorgeFlorian GeorgeFlorian added the bug Something isn't working label Nov 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant