-
Notifications
You must be signed in to change notification settings - Fork 316
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
Crashed to upload large files ( > 500MB): [Terminating app due to uncaught exception 'NSMallocException', reason: 'Failed to grow buffer'] #146
Comments
That's interesting, thanks for reporting. It seems to me as if tus-js-client is trying to read the entire file in memory before uploading it. This works fine if enough memory is available to cover a smaller file but obviously fails for bigger uploads. I am not sure how to fix this inside tus-js-client out of my head now but maybe @arturi knows if React Native has a better way for streaming uploads. @nikolaytsigvintsev: As a workaround you might want to add the |
Hi. Thanks for the answer. I tried to install chunkSize, but it did not help.
|
Oh, I forgot. tus-js-client apparently tries to load the file into memory before it slices it using the In the meantime you might want to look into using https://github.com/vinzscam/react-native-tus-client which is a tus-js-client-like wrapper around the native Android and iOS tus clients. I have never tried them by myself but they should be able to handle bigger files. |
Hi. Thank you for taking the time to respond. The tus-js-client documentation says that you can start the upload with the Readable stream option. I think that one of the ways out of this problem is to create a readable stream and send it to the upload function. Only I cannot create a readable stream (react-native) that I can send in the Upload function. Thanks for help. |
We only implemented uploading from readable stream for the browsers and Node.js, so I doubt that this would work without modifications for React Native. We are happy to extend the support for streaming uploads to React Native if you would like to give it a try.
That's great, would you mind sharing a link with us? |
Hi. Thanks for the answer. I do not know how I can help you. I am new to the react-native. I can try to make a function to upload file by stream, but tell me where to start. |
Hi @nikolaytsigvintsev, we're working on this. We'll have a (very basic) example/version online over at the Uppy site, hopefully today. |
Hi @kvz. I am very glad that your work goes forward. Thanks and good luck. |
Hi @nikolaytsigvintsev, I noticed you said it wasn't working for you in a different thread. it seems we had a typo in there earlier 😱 sad that we're not using TypoScript (pun intended :) ) for examples yet maybe 😹 @ifedapoolarewaju discovered and fixed it here: transloadit/uppy@854654b We've tested this and confirmed it works on an Android simulator. Sorry for the long and dangerous road we're putting you on! Would you mind seeing if this fixes it for you too? Thanks for bearing with us! |
Hi @kvz. Thanks for the answer. Videoreport:
|
@nikolaytsigvintsev there might be something off with your code. How are you instantiating Tus? Are you passing the |
Yes. const upload = new tus.Upload({uri: The getTusFileReader function is called, but slice () in class TusFileReader does not call |
what is the content of |
version of tus-js-client: The getTusFileReader is function in tusFileReader.js: My code for react-native: import RNFetchBlob from 'rn-fetch-blob' export default function getTusFileReader(file, chunkSize, cb) { class TusFileReader { slice(start, end, cb) { close() { } |
so you are using |
Yes. I tried to solve my problem in order to upload large 1G-5G files for 'react-native'. I found an example on expo and took a snippet of code. The example on expo also does not upload large files. I made a video report. |
@nikolaytsigvintsev the So this error is due to your modification. In fact, based on the error in your logs above: export default function getTusFileReader(file, chunkSize, cb) {
RNFetchBlob.fs.stat(file.uri)
.then((stats) => {
console.log('Size file = ', stats.size)
cb(null, new TusFileReader(file, stats.size))
}).catch(cb)
} This line particularly |
Hi. I partially solved the problem.
But all the same there is an error: Thread 47: EXC_RESOURCE RESOURCE_TYPE_MEMORY (limit = 1400 MB, unused = 0x0) Position: start=981467136 : end=989855744 : chunk = 8388608 File size = 1.2GB Somewhere there is a memory leak ? |
Hi. An apparent memory leak occurs with each call function cb(null, base64.toByteArray(data)) Thanks. |
@nikolaytsigvintsev ah, I didn't realize that you weren't setting
How can this memory leak be reproduced? Or maybe you could also share how you arrived at the theory? |
I am very glad that you took the time. A memory leak occurs with each fragment. When debugging, I can see that there is a leak in the CFString module. I now do not know who is to blame or tus-js-client or React-Native Thanks . |
Hello, guys ! I was forced to return to the problem of uploading large files for REACT-NATIVE, and I found that a memory leak occurred while reading the file. While I dealing with this problem. |
That's interesting, thanks for pointing it out, @nikolaytsigvintsev. If there is indeed a memory leak inside react-native-fs, it will be hard/impossible for tus-js-client to work around this. I am unsure if you will get a good support there as the repository has many open issues, but in all honesty, I don't know what to do about it. |
Hello, guys! After a long search for a solution to my problem ( answers from react-native developers were not received. facebook/react-native#26972 ) I returned to trying to upload files using tus-js-client without the chunk method (without fileReader: getTusFileReader parameter).
Please tell me how can I solve this problem? Thanks! |
I am wondering, why did you decide against the fileReader option? I thought that previously worked for you? |
Hi Marius! No. The uploading files doesn't work with fileReader: getTusFileReader parameter. I am reading files by means RNFS (react-native) by chunks and occur the memory leak. I have written about it on 10 May, 10 Jun, 18 Oct. I made a lot of tests and sent the description problem to the developers react-native and react-native-fs:
But the answer no. I decided to turn off fileReader: getTusFileReader parameter and try to upload small files but faced the same problem. I have thought that I have mistakes in my code. Then I have downloaded the example your code (https://github.com/tus/tus-js-client/tree/master/demos/reactnative) but the same problem. I showed it on video. Thanks |
Ok, that's unfortunate to hear. I was at the believe that this feature should solve the problem
No me personally. And I also don't have the time or working environment to reproduce this problem. Maybe @ifedapoolarewaju could have a look at this since he was previously involved? |
Hey, any news regarding this problem? |
Hi, Jahn-Brito Unfortunately, we have postponed this question for now |
@nikolaytsigvintsev I managed to upload it to Vimeo with large files. _upload = new Upload(file, {
uploadUrl: video.url,
retryDelays: [0, 1000, 3000, 5000],
chunkSize: 15 * 1024 * 1024,
fileReader: new TusFileReader(),
uploadSize: video.size,
metadata: {
filename: video.name || video.filename,
filetype: video.mime
},
onError: (error) => onError(video.hashId, error),
onProgress: (bytesAccepted, bytesTotal) => onProgress(video.hashId, bytesAccepted, bytesTotal),
onSuccess: () => onSuccess(video.hashId)
});
_upload.start(); import RNFS from 'react-native-fs'
import base64 from 'base64-js'
export default class TusFileReader {
openFile(input, chunkSize){
return RNFS.stat(input.uri)
.then((stats) => new FileSource(input, stats.size))
.catch((err) => console.tron.log('erro', err))
}
}
class FileSource {
constructor(file, size){
this._file = file
this._size = size
}
async slice(start, end){
end = Math.min(end, this._size)
const length = end - start;
const position = start;
const data = await RNFS.read(this._file.uri, length, position, 'base64')
const value = base64.toByteArray(data)
return Promise.resolve({ value });
}
close(){}
} sources: |
Hi, Jahn-Brito ! Many thanks for the help! I will definitely try and report the result. |
Hey, any news on how did this work using the File Reader ? I am thinking it might be due to the way tus client reads the file on android device and perhaps having a Filereader will fix the issue. Any help appreciated. Thanks |
@divyanshverma This issue is about React Native. Does Ionic Capacitor use React Native under the hood? If not, please open a new issue with more details about the problems that you are seeing. |
it is not working for me i have implemented the same thing and still getting this error *** Terminating app due to uncaught exception 'NSMallocException', reason: 'Failed to grow buffer' |
Hey guys, same for me here ! |
Hi @adrienfloor Unfortunately, we have postponed this question for now. But @jahn-brito said he can transfer large files? |
@nikolaytsigvintsev react-native-tus-client is also throwing the same error, it not allowed the 500 MB + video from devices |
Hi @jahn-brito! I had to go back to using tus-js-client to upload large files. I upgraded to 2.3.0 and updated my fileReader function from your example. Yes ! Yes ! Yes ! I certify that the upload went smoothly and without memory leaks on my Android device.
============================================================== report: @jahn-brito Thanks! Great job! Thanks to everyone who participated in the development of this library! |
Wow, that is amazing news! Congrats 🎉 |
@nikolaytsigvintsev thanks for letting me know about this issue. Did you test if this upload method works while app is in background? |
Hi @swizes ! Yes. This method works in the background for Android and works with iOS restrictions. |
Its working but I'm experiencing FPS drops on JS thread up to -2fps. On Android. (Update) Every time the slice() function in FileSource get triggered it brings down the JS to -2fps#146 chunkSize: 8 * 1024 * 1024 |
Hi @ccharliemagne! Yes. I see it too. Apparently, when a packet is formed for transmission, then all the processing power is used. I am struggling with this by reducing the chunk size to 1MB. 1 * 1024 * 1024. |
What I've seen is that it's the |
Do you know if there is an replacement for the toByteArray function to speed this up? |
I tried a couple of alternatives, but they were all slow. In the end we just figured out that we could do without the custom FileReader, so I didn't get so far as to profile the running code and see precisely what was slow. But an educated guess would be that it is because converting a base64 encoded string to a byte array in an inherently computationally intensive operation and the js runtime in React Native does not have a jit compiler[0] and only an interpreter. An interpreter will run code muuuuch slower than jit compiled code, and computationally intensive code like this will be hit especially hard by this slowdown. |
@samal-rasmussen Ah, thank you for the insights. So if I understand correctly, you are just using the FileReader that is built into tus-js-client? I.e. this one: tus-js-client/lib/browser/fileReader.js Lines 9 to 19 in c0b5a7d
|
Hey guys, i am trying to upload large file and faced the same issue with the ios and android memory fills up and crash the app. Using React native as well. i switched from axios to your client and i tried to implement the above solution without luck. I am using Expo Picker -> will yield a uri for me and pass it to new tus.Upload(fileUrl, {}) with options as stated above but i always get |
Could you post some more info about the error? Any stack or line which it crashes on? |
[Wed Feb 15 2023 02:21:43.400] LOG [TypeError: undefined is not an object (evaluating 'path.startsWith')] this is the error i get. I am not sure thought if i need to change my backend to be tus compatible or i can just use it with normal multipart/formdata |
if you want to use tus-js-client you need to have a tus compatible backend. the official recommended one is https://github.com/tus/tusd did you try this code? #146 (comment) |
i will try it with a compatible backend |
getting this error. |
See tus/tusd#909 |
Hi.
I'm trying to upload a large file. My application crashes after launching the upload with the error:
On a small file size works well.
Code:
The text was updated successfully, but these errors were encountered: