-
Notifications
You must be signed in to change notification settings - Fork 10.1k
Setting a timer for a long period of time warning #3054
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
Comments
add {pingTimeout: 30000}to where you tie socket.io to your http server var io = socketio(server, {pingTimeout: 30000});
``` or some other amount it defaults to 85000 which is more then RN likes |
@KingCosmic not work for me |
Is your issue the same as the o e here? @ikgsanalatsary |
does not work for me either |
Same warning... but not working for me either @KingCosmic :/ |
Facing the same issue, any news? |
did you try configuring socket timeout |
@KingCosmic tried with |
@KingCosmic I tried both in server side & RN. But the yellow warning still show |
Why am I the only one be here ;-; @ikhsanalatsary what is your error exactly and @matthieupinte server side should be fine how are you connecting socket.io to your http server? |
@ikhsanalatsary set the ping timeout server side not client side and it should be fixed |
That's what fixed it for me anyways |
does not work |
on the server side do this:
|
|
This fixes the yellow box and the console log. It even fixes it for Expo. Simply place the following script at the beginning of your codebase. import { YellowBox } from 'react-native';
import _ from 'lodash';
YellowBox.ignoreWarnings(['Setting a timer']);
const _console = _.clone(console);
console.warn = message => {
if (message.indexOf('Setting a timer') <= -1) {
_console.warn(message);
}
}; |
I've encapsulated the previous logic into two npm modules, one for general node/javascript and one for react-native. The react-native module is compatible with expo apps. https://github.com/jamrizzi/ignore-warnings You would use it the following way . . . import ignoreWarnings from 'react-native-ignore-warnings';
ignoreWarnings('Setting a timer'); |
As noted above, I think setting |
after some more looking around, pingTimeout fixed it on iOS but on android it still showed up but as said above pingInterval might fix that |
@ikhsanalatsary Hello, Can it be used in the react native project? I plan to use it. Please advise. |
@giantss can what be used in the react native project? |
@jamrizzi socket.io |
Its works after I update socket.io in the server and did
As @aprilmintacpineda mentioned |
@ikhsanalatsary Are you using socket.io-client in react native? |
@giantss yes |
@ikhsanalatsary thanks, Could you provide some of the core client-side initialization code? Have you used webscoket? |
const socket = io(api.BASE_API_URL, {
transports: ['websocket'] // you need to explicitly tell it to use websockets
})
class RootContainer extends PureComponent<Props> {
// class body
} put it outside on your root component |
Your reply is very helpful to me, thank you very much. |
@ikhsanalatsary Hello, do you have encountered the following warning in the integration process?
How do you solve this warning? |
@giantss I'm not sure what the real solution is yet, but you can at least hide the error for now. Refer to my previous comments. |
@jamrizzi Thank you for your answer, I have seen this solution before, I do not know what better solution |
@giantss, yeah I wish I had a better answer. |
@jamrizzi @giantss did you try the answer from @aprilmintacpineda above? const io = socketIO(server, {
pingTimeout: 5000 // this will be the default starting version 2.1.0 (currently it's 60000)
}); |
@darrachequesne I tried this solution but it has no effect. @ikhsanalatsary He also encountered this warning. I don't know if he has solved it perfectly. |
@giantss That's weird. Can you paste the code of your |
@aprilmintacpineda Thank you for your advice.This warning appears in the react native app. |
@giantss Yes, it does. Please post the |
@giantss if you followed my advice above, you should have a code like this on the backend. // .. other codes
server.listen(9000, () => {
console.log('Dev server is running on http(s)://localhost:9000.');
console.log('http(s)://10.0.22:9000 for android');
});
/**
* socket.io
*/
import socketIO from 'socket.io';
const io = socketIO(server, {
pingTimeout: 30000,
pingInterval: 30000
});
// .. other codes
io.on('connection', socket => {
// events
}); |
@aprilmintacpineda I use the
then restart the server, the problem still exists. |
have you done |
The version used in the demo is |
Thanks @aprilmintacpineda
in server side. |
@giantss use latest version |
all solutions mentioned here, do not solve this issue for me.... except, hiding the warning... |
Unfortunately I have no control over the server side so I can't change the timeout. Why is this a server side issue to start with though? |
for whoever doesn't work, restart you server.... tried like 20 times... stupid me :D |
@codejamninja thanks..it fixed it for Android... Plz I want to know all the warnings this api can fix..thanks |
For future readers: the default So the complete delay (pingTimeout + pingInterval) is now 30s, which is below the RN threshold of 60s. Note: this value may be a bit too small, as it may cause ping timeouts when uploading big files. Please increase it if needed. Documentation here. |
This value was updated from 60000 to 5000 in [1], included in `[email protected]` (Feb 2018). The reasoning back then: Some users experienced long delays between disconnection on the server-side and on the client-side. The "disconnect" event would take a long time to fire in the browser, probably due to a timer being delayed. Hence the change. That being said, the current value (5s) now causes unexpected disconnections when a big payload is sent over a slow network, because it prevents the ping-pong packets from being exchanged between the client and the server. This can also happen when a synchronous task blocks the server for more than 5 seconds. The new value (20s) thus seems like a good balance between quick disconnection detection and tolerance to various delays. Note: pingInterval + pingTimeout is still below the threshold of React Native, which complains if a timer is set with a delay of more than 1 minute. [1]: 65b1ad1 Related: - socketio/socket.io#2770 - socketio/socket.io#2769 - socketio/socket.io#3054 - socketio/socket.io#3376
This value was updated from 60000 to 5000 in [1], included in `[email protected]` (Feb 2018). The reasoning back then: Some users experienced long delays between disconnection on the server-side and on the client-side. The "disconnect" event would take a long time to fire in the browser, probably due to a timer being delayed. Hence the change. That being said, the current value (5s) now causes unexpected disconnections when a big payload is sent over a slow network, because it prevents the ping-pong packets from being exchanged between the client and the server. This can also happen when a synchronous task blocks the server for more than 5 seconds. The new value (20s) thus seems like a good balance between quick disconnection detection and tolerance to various delays. Note: pingInterval + pingTimeout is still below the threshold of React Native, which complains if a timer is set with a delay of more than 1 minute. [1]: 65b1ad1 Related: - socketio/socket.io#2770 - socketio/socket.io#2769 - socketio/socket.io#3054 - socketio/socket.io#3376 Backported from 5a7fa13
Hi, I'm getting the following warnings when using socket.io with my React Native project.
I'm on React Native version 0.44.3
and socket.io-client: 1.5.1
Any ideas of how to solve or is this a bug? It seems to be slowing my whole app down significantly, as well as producing lots of console warnings.
Here is the error in the console:
Setting a timer for a long period of time, i.e. multiple minutes, is a performance and correctness issue on Android as it keeps the timer module awake, and timers can only be called when the app is in the foreground. See facebook/react-native#12981 for more info.
(Saw setTimeout with duration 85000ms)
console.warn @ index.android.bundle:40843
setTimeout @ index.android.bundle:3412
Socket.onHeartbeat @ index.android.bundle:72517
Emitter.emit @ index.android.bundle:74290
Socket.onPacket @ index.android.bundle:72470
(anonymous) @ index.android.bundle:72336
Emitter.emit @ index.android.bundle:74290
Transport.onPacket @ index.android.bundle:73298
Transport.onData @ index.android.bundle:73294
ws.onmessage @ index.android.bundle:74952
dispatchEvent @ index.android.bundle:13268
(anonymous) @ index.android.bundle:12969
emit @ index.android.bundle:3853
__callFunction @ index.android.bundle:2092
(anonymous) @ index.android.bundle:1950
__guard @ index.android.bundle:2064
callFunctionReturnFlushedQueue @ index.android.bundle:1949
(anonymous) @ debuggerWorker.js:71
index.android.bundle:40843 Remote debugger is in a background tab which may cause apps to perform slowly. Fix this by foregrounding the tab (or opening it in a separate window).
console.warn @ index.android.bundle:40843
(anonymous) @ debuggerWorker.js:25
(anonymous) @ debuggerWorker.js:53
Thanks
The text was updated successfully, but these errors were encountered: