Express request fires a second time Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Express request is called twiceHow is an HTTP POST request made in node.js?How to access the GET parameters after “?” in Express?PassportJS in Nodejs never call the callback functionNodejs Express sendStatus errorMy Express 4.13.1 app listens on 2 different portsHow do I connect a react frontend and express backend?JavaScript and CSS files not linking in App (using Express)Concurrent in NodejsWhy express.Router() while separating routesHow to send github OAuth data to client?

Multi tool use
Multi tool use

How much damage would a cupful of neutron star matter do to the Earth?

What does Turing mean by this statement?

What would you call this weird metallic apparatus that allows you to lift people?

Lagrange four-squares theorem --- deterministic complexity

Is multiple magic items in one inherently imbalanced?

Would it be easier to apply for a UK visa if there is a host family to sponsor for you in going there?

Strange behavior of Object.defineProperty() in JavaScript

The Nth Gryphon Number

How many morphisms from 1 to 1+1 can there be?

Is CEO the "profession" with the most psychopaths?

Why are vacuum tubes still used in amateur radios?

How many time has Arya actually used Needle?

Sentence with dass with three Verbs (One modal and two connected with zu)

What does it mean that physics no longer uses mechanical models to describe phenomena?

Has negative voting ever been officially implemented in elections, or seriously proposed, or even studied?

What does 丫 mean? 丫是什么意思?

Is there public access to the Meteor Crater in Arizona?

How do I tell what width chain my used chainring needs?

A term for a woman complaining about things/begging in a cute/childish way

Why we try to capture variability?

preposition before coffee

How to align multiple equations

Should a wizard buy fine inks every time he want to copy spells into his spellbook?

Is it possible for SQL statements to execute concurrently within a single session in SQL Server?



Express request fires a second time



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30UTC (7:30pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!Express request is called twiceHow is an HTTP POST request made in node.js?How to access the GET parameters after “?” in Express?PassportJS in Nodejs never call the callback functionNodejs Express sendStatus errorMy Express 4.13.1 app listens on 2 different portsHow do I connect a react frontend and express backend?JavaScript and CSS files not linking in App (using Express)Concurrent in NodejsWhy express.Router() while separating routesHow to send github OAuth data to client?



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








3















I'm at a little standstill here.



I'm creating an express app that have to export a huge amount of data from a Shopify store with a single request.



The issue is that when I reach the 2min mark the request is fired again ( since the default timeout is 2min ), so I increased the server.setTimeout() to take in consideration the time that it needs.



So this fixed the fire of the request on the 2min mark, but once my request finish, once again for some reason a second request is made.



Here is a bare bone example of the issue:






const express = require('express');

function sleep(ms)
return new Promise(resolve=>
setTimeout(resolve,ms)
)


app.get('/export', async (req, res) =>
// Sleep for 2:03min
await sleep(123000);
console.log('Starting request');
res.status(200).send('Finish');
)

const server = app.listen(3000, () =>
console.log(`Example app listening on port $port`)
)
// Set timeout to 2:04min
server.setTimeout(124000);





If you open http://localhost:3000/export the result form the above code returns:



Starting request <- at the beginning



Starting request <- at the 2:04 mark



Is this some issue because of the async/await, since it seems that res.send() never fires ?



Can someone clarify "why" is this happening and "how" to prevent it?



PS: I can't use a flag or something to check if the request was already made, since the APP needs to work for users exporting the data at the same time, and the second request comes as a brand new one.










share|improve this question






















  • Did you try these things? Also, try wrapping it in a try-catch to see if there are any silent errors due to the async function

    – Fredrik S
    Mar 22 at 11:25











  • @Fredrik S it seems that the issue there is that the request are called instantly, for me it keeps calling it without an end, so it seems that the res.status(200).send('Finish'); is not firing at all.

    – drip
    Mar 22 at 11:29











  • In the promise constructor, why don't you have reject parameter but only resolve? and also resolve has to be called within setTimeout, not passed as function to be executed.

    – Kiran Mathew Mohan
    Mar 22 at 11:29











  • @Kiran Mathew Mohan the provided example is only bare bone to show the issue. There is no actual sleep in my code, but I have to make a "dummy" request for 2 min in some way. Promise allows to be resolved without reject and since resolve() is a function you can call it as a setTimeout function. You even can call it like so Promise.resolve() which is valid as well.

    – drip
    Mar 22 at 11:41












  • @drip for me this works just as supposed. Try disabling all extension to make sure it's not because of one of them.

    – F0G
    Mar 22 at 11:57

















3















I'm at a little standstill here.



I'm creating an express app that have to export a huge amount of data from a Shopify store with a single request.



The issue is that when I reach the 2min mark the request is fired again ( since the default timeout is 2min ), so I increased the server.setTimeout() to take in consideration the time that it needs.



So this fixed the fire of the request on the 2min mark, but once my request finish, once again for some reason a second request is made.



Here is a bare bone example of the issue:






const express = require('express');

function sleep(ms)
return new Promise(resolve=>
setTimeout(resolve,ms)
)


app.get('/export', async (req, res) =>
// Sleep for 2:03min
await sleep(123000);
console.log('Starting request');
res.status(200).send('Finish');
)

const server = app.listen(3000, () =>
console.log(`Example app listening on port $port`)
)
// Set timeout to 2:04min
server.setTimeout(124000);





If you open http://localhost:3000/export the result form the above code returns:



Starting request <- at the beginning



Starting request <- at the 2:04 mark



Is this some issue because of the async/await, since it seems that res.send() never fires ?



Can someone clarify "why" is this happening and "how" to prevent it?



PS: I can't use a flag or something to check if the request was already made, since the APP needs to work for users exporting the data at the same time, and the second request comes as a brand new one.










share|improve this question






















  • Did you try these things? Also, try wrapping it in a try-catch to see if there are any silent errors due to the async function

    – Fredrik S
    Mar 22 at 11:25











  • @Fredrik S it seems that the issue there is that the request are called instantly, for me it keeps calling it without an end, so it seems that the res.status(200).send('Finish'); is not firing at all.

    – drip
    Mar 22 at 11:29











  • In the promise constructor, why don't you have reject parameter but only resolve? and also resolve has to be called within setTimeout, not passed as function to be executed.

    – Kiran Mathew Mohan
    Mar 22 at 11:29











  • @Kiran Mathew Mohan the provided example is only bare bone to show the issue. There is no actual sleep in my code, but I have to make a "dummy" request for 2 min in some way. Promise allows to be resolved without reject and since resolve() is a function you can call it as a setTimeout function. You even can call it like so Promise.resolve() which is valid as well.

    – drip
    Mar 22 at 11:41












  • @drip for me this works just as supposed. Try disabling all extension to make sure it's not because of one of them.

    – F0G
    Mar 22 at 11:57













3












3








3








I'm at a little standstill here.



I'm creating an express app that have to export a huge amount of data from a Shopify store with a single request.



The issue is that when I reach the 2min mark the request is fired again ( since the default timeout is 2min ), so I increased the server.setTimeout() to take in consideration the time that it needs.



So this fixed the fire of the request on the 2min mark, but once my request finish, once again for some reason a second request is made.



Here is a bare bone example of the issue:






const express = require('express');

function sleep(ms)
return new Promise(resolve=>
setTimeout(resolve,ms)
)


app.get('/export', async (req, res) =>
// Sleep for 2:03min
await sleep(123000);
console.log('Starting request');
res.status(200).send('Finish');
)

const server = app.listen(3000, () =>
console.log(`Example app listening on port $port`)
)
// Set timeout to 2:04min
server.setTimeout(124000);





If you open http://localhost:3000/export the result form the above code returns:



Starting request <- at the beginning



Starting request <- at the 2:04 mark



Is this some issue because of the async/await, since it seems that res.send() never fires ?



Can someone clarify "why" is this happening and "how" to prevent it?



PS: I can't use a flag or something to check if the request was already made, since the APP needs to work for users exporting the data at the same time, and the second request comes as a brand new one.










share|improve this question














I'm at a little standstill here.



I'm creating an express app that have to export a huge amount of data from a Shopify store with a single request.



The issue is that when I reach the 2min mark the request is fired again ( since the default timeout is 2min ), so I increased the server.setTimeout() to take in consideration the time that it needs.



So this fixed the fire of the request on the 2min mark, but once my request finish, once again for some reason a second request is made.



Here is a bare bone example of the issue:






const express = require('express');

function sleep(ms)
return new Promise(resolve=>
setTimeout(resolve,ms)
)


app.get('/export', async (req, res) =>
// Sleep for 2:03min
await sleep(123000);
console.log('Starting request');
res.status(200).send('Finish');
)

const server = app.listen(3000, () =>
console.log(`Example app listening on port $port`)
)
// Set timeout to 2:04min
server.setTimeout(124000);





If you open http://localhost:3000/export the result form the above code returns:



Starting request <- at the beginning



Starting request <- at the 2:04 mark



Is this some issue because of the async/await, since it seems that res.send() never fires ?



Can someone clarify "why" is this happening and "how" to prevent it?



PS: I can't use a flag or something to check if the request was already made, since the APP needs to work for users exporting the data at the same time, and the second request comes as a brand new one.






const express = require('express');

function sleep(ms)
return new Promise(resolve=>
setTimeout(resolve,ms)
)


app.get('/export', async (req, res) =>
// Sleep for 2:03min
await sleep(123000);
console.log('Starting request');
res.status(200).send('Finish');
)

const server = app.listen(3000, () =>
console.log(`Example app listening on port $port`)
)
// Set timeout to 2:04min
server.setTimeout(124000);





const express = require('express');

function sleep(ms)
return new Promise(resolve=>
setTimeout(resolve,ms)
)


app.get('/export', async (req, res) =>
// Sleep for 2:03min
await sleep(123000);
console.log('Starting request');
res.status(200).send('Finish');
)

const server = app.listen(3000, () =>
console.log(`Example app listening on port $port`)
)
// Set timeout to 2:04min
server.setTimeout(124000);






node.js express






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 22 at 10:53









dripdrip

6,20511534




6,20511534












  • Did you try these things? Also, try wrapping it in a try-catch to see if there are any silent errors due to the async function

    – Fredrik S
    Mar 22 at 11:25











  • @Fredrik S it seems that the issue there is that the request are called instantly, for me it keeps calling it without an end, so it seems that the res.status(200).send('Finish'); is not firing at all.

    – drip
    Mar 22 at 11:29











  • In the promise constructor, why don't you have reject parameter but only resolve? and also resolve has to be called within setTimeout, not passed as function to be executed.

    – Kiran Mathew Mohan
    Mar 22 at 11:29











  • @Kiran Mathew Mohan the provided example is only bare bone to show the issue. There is no actual sleep in my code, but I have to make a "dummy" request for 2 min in some way. Promise allows to be resolved without reject and since resolve() is a function you can call it as a setTimeout function. You even can call it like so Promise.resolve() which is valid as well.

    – drip
    Mar 22 at 11:41












  • @drip for me this works just as supposed. Try disabling all extension to make sure it's not because of one of them.

    – F0G
    Mar 22 at 11:57

















  • Did you try these things? Also, try wrapping it in a try-catch to see if there are any silent errors due to the async function

    – Fredrik S
    Mar 22 at 11:25











  • @Fredrik S it seems that the issue there is that the request are called instantly, for me it keeps calling it without an end, so it seems that the res.status(200).send('Finish'); is not firing at all.

    – drip
    Mar 22 at 11:29











  • In the promise constructor, why don't you have reject parameter but only resolve? and also resolve has to be called within setTimeout, not passed as function to be executed.

    – Kiran Mathew Mohan
    Mar 22 at 11:29











  • @Kiran Mathew Mohan the provided example is only bare bone to show the issue. There is no actual sleep in my code, but I have to make a "dummy" request for 2 min in some way. Promise allows to be resolved without reject and since resolve() is a function you can call it as a setTimeout function. You even can call it like so Promise.resolve() which is valid as well.

    – drip
    Mar 22 at 11:41












  • @drip for me this works just as supposed. Try disabling all extension to make sure it's not because of one of them.

    – F0G
    Mar 22 at 11:57
















Did you try these things? Also, try wrapping it in a try-catch to see if there are any silent errors due to the async function

– Fredrik S
Mar 22 at 11:25





Did you try these things? Also, try wrapping it in a try-catch to see if there are any silent errors due to the async function

– Fredrik S
Mar 22 at 11:25













@Fredrik S it seems that the issue there is that the request are called instantly, for me it keeps calling it without an end, so it seems that the res.status(200).send('Finish'); is not firing at all.

– drip
Mar 22 at 11:29





@Fredrik S it seems that the issue there is that the request are called instantly, for me it keeps calling it without an end, so it seems that the res.status(200).send('Finish'); is not firing at all.

– drip
Mar 22 at 11:29













In the promise constructor, why don't you have reject parameter but only resolve? and also resolve has to be called within setTimeout, not passed as function to be executed.

– Kiran Mathew Mohan
Mar 22 at 11:29





In the promise constructor, why don't you have reject parameter but only resolve? and also resolve has to be called within setTimeout, not passed as function to be executed.

– Kiran Mathew Mohan
Mar 22 at 11:29













@Kiran Mathew Mohan the provided example is only bare bone to show the issue. There is no actual sleep in my code, but I have to make a "dummy" request for 2 min in some way. Promise allows to be resolved without reject and since resolve() is a function you can call it as a setTimeout function. You even can call it like so Promise.resolve() which is valid as well.

– drip
Mar 22 at 11:41






@Kiran Mathew Mohan the provided example is only bare bone to show the issue. There is no actual sleep in my code, but I have to make a "dummy" request for 2 min in some way. Promise allows to be resolved without reject and since resolve() is a function you can call it as a setTimeout function. You even can call it like so Promise.resolve() which is valid as well.

– drip
Mar 22 at 11:41














@drip for me this works just as supposed. Try disabling all extension to make sure it's not because of one of them.

– F0G
Mar 22 at 11:57





@drip for me this works just as supposed. Try disabling all extension to make sure it's not because of one of them.

– F0G
Mar 22 at 11:57












1 Answer
1






active

oldest

votes


















1














Well I lost around 4 hours on this today and the conclusion is that my tunel service ( http://serveo.net/ ) was firing another request at some point perfectly timed when my export is done. ( as for why, I don't have an answer to that ) I'm still not sure if this is the correct conclusion, but switching to a different option ( or using the direct localhost ) didn't show any issues.



I moved to OpenVPN and all of my problems were gone. Ngrok was OK as well, but since the free version didn't have a fixed URL ( and it's a pain to change all of the end points in the App setup each day I start the service ) I went with OpenVPN.



The root of the problem was that res.status(200).send('Finish') was never firing for some specific reason or if it was it sure didn't seems so.



Thanks for all of the help.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55298070%2fexpress-request-fires-a-second-time%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Well I lost around 4 hours on this today and the conclusion is that my tunel service ( http://serveo.net/ ) was firing another request at some point perfectly timed when my export is done. ( as for why, I don't have an answer to that ) I'm still not sure if this is the correct conclusion, but switching to a different option ( or using the direct localhost ) didn't show any issues.



    I moved to OpenVPN and all of my problems were gone. Ngrok was OK as well, but since the free version didn't have a fixed URL ( and it's a pain to change all of the end points in the App setup each day I start the service ) I went with OpenVPN.



    The root of the problem was that res.status(200).send('Finish') was never firing for some specific reason or if it was it sure didn't seems so.



    Thanks for all of the help.






    share|improve this answer



























      1














      Well I lost around 4 hours on this today and the conclusion is that my tunel service ( http://serveo.net/ ) was firing another request at some point perfectly timed when my export is done. ( as for why, I don't have an answer to that ) I'm still not sure if this is the correct conclusion, but switching to a different option ( or using the direct localhost ) didn't show any issues.



      I moved to OpenVPN and all of my problems were gone. Ngrok was OK as well, but since the free version didn't have a fixed URL ( and it's a pain to change all of the end points in the App setup each day I start the service ) I went with OpenVPN.



      The root of the problem was that res.status(200).send('Finish') was never firing for some specific reason or if it was it sure didn't seems so.



      Thanks for all of the help.






      share|improve this answer

























        1












        1








        1







        Well I lost around 4 hours on this today and the conclusion is that my tunel service ( http://serveo.net/ ) was firing another request at some point perfectly timed when my export is done. ( as for why, I don't have an answer to that ) I'm still not sure if this is the correct conclusion, but switching to a different option ( or using the direct localhost ) didn't show any issues.



        I moved to OpenVPN and all of my problems were gone. Ngrok was OK as well, but since the free version didn't have a fixed URL ( and it's a pain to change all of the end points in the App setup each day I start the service ) I went with OpenVPN.



        The root of the problem was that res.status(200).send('Finish') was never firing for some specific reason or if it was it sure didn't seems so.



        Thanks for all of the help.






        share|improve this answer













        Well I lost around 4 hours on this today and the conclusion is that my tunel service ( http://serveo.net/ ) was firing another request at some point perfectly timed when my export is done. ( as for why, I don't have an answer to that ) I'm still not sure if this is the correct conclusion, but switching to a different option ( or using the direct localhost ) didn't show any issues.



        I moved to OpenVPN and all of my problems were gone. Ngrok was OK as well, but since the free version didn't have a fixed URL ( and it's a pain to change all of the end points in the App setup each day I start the service ) I went with OpenVPN.



        The root of the problem was that res.status(200).send('Finish') was never firing for some specific reason or if it was it sure didn't seems so.



        Thanks for all of the help.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 22 at 13:13









        dripdrip

        6,20511534




        6,20511534





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55298070%2fexpress-request-fires-a-second-time%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            GG2MMhya PvkT1I
            tuv ElUobcd4,7fwF5I9O3b5UnrhvysjJGmvk 53m6gFX,f5

            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현