Skip to content

Bug Report: RNFS.downloadFile crashes with null pointer when server sends TCP RST (connection reset) #1258

@Yakovyakov

Description

@Yakovyakov

Bug Report: RNFS.downloadFile crashes with null pointer when server sends TCP RST (connection reset)

Problem Description

When RNFS.downloadFile() attempts to download from a server that sends a TCP RST (reset packet), the app crashes with a null pointer exception in native code instead of properly rejecting the promise with a network error.

Environment

  • react-native-fs: 2.20.0
  • React Native: 0.82.1
  • Bug Report: RNFS.downloadFile crashes with null pointer when server sends TCP RST (connection reset)

Problem Description

When RNFS.downloadFile() attempts to download from a server that sends a TCP RST (reset packet), the app crashes with a null pointer exception in native code instead of properly rejecting the promise with a network error.

Environment

  • react-native-fs: 2.20.0
  • React Native: 0.72.0
  • Platform: Android
  • Device: Multiple Android devices

Steps to Reproduce

  1. Set up a server that rejects connections with TCP RST (e.g., port closed, firewall blocking)
  2. Attempt to download using RNFS.downloadFile()
  3. Observe app crash instead of graceful error handling

Code to Reproduce

import RNFS from 'react-native-fs';

async function testDownload() {
  try {
    // Server that will send TCP RST (e.g., port 81 on a server that only has port 80 open)
    const result = await RNFS.downloadFile({
      fromUrl: 'https://example.com:81/nonexistent.apk',
      toFile: `${RNFS.DocumentDirectoryPath}/test.apk`,
      readTimeout: 30000,
      connectionTimeout: 30000,
    }).promise;
    
    console.log('Success:', result); // Never reached
  } catch (error) {
    console.log('Error caught:', error); // Never reached - app crashes
  }
}

### Steps to Reproduce
1. Set up a server that rejects connections with TCP RST (e.g., port closed, firewall blocking)
2. Attempt to download using `RNFS.downloadFile()`
3. Observe app crash instead of graceful error handling

### Code to Reproduce
```javascript
import RNFS from 'react-native-fs';

async function testDownload() {
  try {
    // Server that will send TCP RST (e.g., port 81 on a server that only has port 80 open)
    const result = await RNFS.downloadFile({
      fromUrl: 'https://example.com:81/nonexistent.apk',
      toFile: `${RNFS.DocumentDirectoryPath}/test.apk`,
      readTimeout: 30000,
      connectionTimeout: 30000,
    }).promise;
    
    console.log('Success:', result); // Never reached
  } catch (error) {
    console.log('Error caught:', error); // Never reached - app crashes
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions