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

[Bug?]: RedwoodJS Deploy to Vercel with a vercel.json in the project causes the deploy to loop for 10minutes on vercel #10022

Open
1 task done
RinKimLaw opened this issue Feb 16, 2024 · 36 comments · May be fixed by #10891
Open
1 task done
Assignees
Labels
bug/confirmed We have confirmed this is a bug bug/repro-available A reproduction exists and needs to be confirmed topic/deployment

Comments

@RinKimLaw
Copy link

What's not working?

This is my vercel.json

{
  "functions": {
    "api/src/functions/minutesync/minutesync.*": {
      "memory": 256,
      "runtime": "@vercel/[email protected]"
    },
    "api/src/functions/asauth/asauth.*": {
      "memory": 512,
      "runtime": "@vercel/[email protected]"
    },
    "api/src/functions/ascallback/ascallback.*": {
      "memory": 128,
      "runtime":"@vercel/[email protected]"
    },
    "api/src/functions/asrefresh/asrefresh.*": {
      "memory": 256,
      "runtime":"@vercel/[email protected]"
    },
    "api/src/functions/bulksync/bulksync.*": {
      "memory": 128,
      "runtime":"@vercel/[email protected]"
    },
    "api/src/functions/graphql.*": {
      "memory": 512,
      "runtime":"@vercel/[email protected]"
    }
  }
}

My project config is defaults for a redwoodjs project on [email protected].

With the vercel.json the build keeps looping again and again for 8-10 minutes and then eventually succeeds

Without the vercel.json the build succeeds in 1m30s

I'm guessing Vercel's default config for RedwoodJS projects is somehow being overridden by my vercel.json, causing this looping behaviour.

How do we reproduce the bug?

Create a new project with RedwoodJS typescript and setup a vercel deploy. Add a vercel.json to the project with some config for the functions.

What's your environment? (If it applies)

System:
    OS: Windows 10 10.0.19045
  Binaries:
    Node: 18.19.0 - ~\AppData\Local\Temp\yarn--1708063642733-0.2390738274290265\node.CMD
    Yarn: 1.22.17 - ~\AppData\Local\Temp\yarn--1708063642733-0.2390738274290265\yarn.CMD
  Browsers:
    Chrome: 121.0.6167.185
    Edge: Chromium (121.0.2277.112)
  npmPackages:
    @redwoodjs/core: 6.6.4 => 6.6.4

Are you interested in working on this?

  • I'm interested in working on this
@RinKimLaw RinKimLaw added the bug/needs-info More information is needed for reproduction label Feb 16, 2024
@jtoar
Copy link
Contributor

jtoar commented Feb 17, 2024

Hey @RinKimLaw I tried making a repro (albeit with just the graphql function) and couldn't reproduce 8-10 minute looping builds. One thing I'm wondering: is the @vercel/redwood package a Vercel runtime? Basically, where did you see docs to use that package as the runtime, or did Vercel support tip you off to that?

I'm wondering if that's the problem. I feel like maybe you should actually end up using the Node.js runtime via @vercel/node?

@timoshishi
Copy link

Hi @jtoar, I'm running into the same issue here trying to extend my function timeouts.

The selection of the runtime is referenced in the docs here. It seems this was suggested by vercel support to a user in this community post.

As it stands, the default deploy that runs the @redwood/vercel builder is not picking up the maxDuration property being exported from my functions so function executions are limited to 15 seconds even on the Pro plan.

@timoshishi
Copy link

It appears that targeting the root graphql file only will allow you to customize options for the server file but not the nested functions. Building will succeed with this configuration

{
  "functions": {
    "api/src/functions/*.*": {
      "maxDuration": 20,
      "runtime": "@vercel/[email protected]"
    }
}

Attempting to set options for a nested function will result in recursive builds

{
  "functions": {
    "api/src/functions/*.*": {
      "maxDuration": 20,
      "runtime": "@vercel/[email protected]"
    },
    "api/src/functions/nestedFunction/*.*": {
      "maxDuration": 300,
      "runtime": "@vercel/[email protected]"
    }
  }
}

I have verified this both with the local vercel build command and in the platform builds.

This restricts customization and pretty much rules out vercel as viable platform for all but the most simple apps built with redwood.

For context I am also running "@redwoodjs/core": "6.6.0"

@RinKimLaw
Copy link
Author

RinKimLaw commented Feb 27, 2024

I think there's a way to configure the vercel.json for redwoodjs that's not completely/accurately documented anywhere because with the default settings (No vercel.json), the project deploys within 1m30s. Also, all the config in my vercel.json is ignored, the memory size is always the default 1024MB.

@dthyresson
Copy link
Contributor

dthyresson commented Mar 4, 2024

I believe that https://community.redwoodjs.com/t/increase-timeout-duration-of-api-in-vercel/5446/3 address this issue with some docs to set the timeout on Vercel.

But I may be wrong?

@dthyresson
Copy link
Contributor

Just to clarify - this issue related to the length of the build time (not the timeout of the function) -- because Vercel is building the redwoodJS app multiple times (once per api/function)?

@timoshishi
Copy link

@dthyresson That documentation only works for the base graphql function. If you try to specify a different timeout or memory settings for the serverless functions in sub-directories, it will build recursively, not just once per function

@RinKimLaw
Copy link
Author

I wonder if there's any update on this? I previously tried to post this as an issue on Vercel's github but couldn't get through. For now it's fine deploying Redwood to vercel with default settings for me, but it's a pretty major issue that neither the function size nor the function timeout can be adjusted using vercel.json.

@dthyresson
Copy link
Contributor

Hi @RinKimLaw - I am trying to remember the details but does this https://redwoodjs.com/docs/deploy/vercel#verceljson-configuration help?

I imagine that one might have to specify a function (not the GraphQL function listed)..

I’d this does not help, could you share an example that does not work as expected?

@RinKimLaw
Copy link
Author

@dthyresson No that config didn't work for me. It eventually deploys after recursively building everything, but neither of the function parameters are honoured (Memory or timeout).

@RinKimLaw
Copy link
Author

Opened an issue on Vercel's side https://github.com/orgs/vercel/discussions/6526

@dthyresson
Copy link
Contributor

@RinKimLaw We will likely have to create a small reproducible case for Vercel to try. Do you have a public repo of a project we can share or could you post the Vercel config you are using to make sure we’re doing the same. Thanks.

@RinKimLaw
Copy link
Author

@dthyresson I can setup a public repo tomorrow to demo the issue.

@dthyresson
Copy link
Contributor

@dthyresson I can setup a public repo tomorrow to demo the issue.

Thank you so much! This will really help as I can share with Vercel, too.

@DrakenKor
Copy link

Hi, just on my personal account -
Here is the test repo - https://github.com/DrakenKor/vercel-redwood-tester
Vercel.json values:

{
  "buildCommand": "yarn rw build",
  "functions": {
    "api/src/functions/tester1/tester1.*": {
      "memory": 256,
      "runtime": "@vercel/[email protected]",
      "maxDuration": 20
    },
    "api/src/functions/graphql.*": {
      "memory": 512,
      "runtime":"@vercel/[email protected]",
      "maxDuration": 30
    }
  }
}

image

Values are not honoured for the tester1 function. The build is also recursive and builds twice, once for each function.

@DrakenKor
Copy link

Vercel deploy settings:
image

@bencohen4
Copy link

We are still experiencing this issue months later, to great frustration. Same issue as @DrakenKor

@dthyresson
Copy link
Contributor

Hi @bencohen4 have you spoken with to Vercel? Did they give any insight?

I’ll connect with them to understand how they build and try to reproduce.

I haven’t deployed to Vercel recently. Do they have a local build process like Netlify does that builds locally like they would when deployed?

@bencohen4
Copy link

Hi @bencohen4 have you spoken with to Vercel? Did they give any insight?

I’ll connect with them to understand how they build and try to reproduce.

I haven’t deployed to Vercel recently. Do they have a local build process like Netlify does that builds locally like they would when deployed?

Hi @dthyresson I did open up a support ticket with Vercel, they did offer some suggestions but those didn't end up working unfortunately. The case was dropped around the end of January.

They do have a local vercel build command.

CC'ing @will-govwell for visibility

@dthyresson
Copy link
Contributor

dthyresson commented Jun 26, 2024

Vercel got back to me and I’ll try my own deploy to reproduce. For reference: theypointed me to the redwood build “adapter” https://github.com/vercel/vercel/blob/main/packages/redwood/src/index.ts

Also could people @bencohen4 and others share the Vercel config they use?

Does it specify the runtime? One thing we want to try is if the runtime setting is removed from each function config.

The hypothesis to test is that this build handler is called when a Redwood app builds. By setting that runtime in effect one says build the function with this very same build handler again .. and again per function.

If no runtime is defined then we think the config should just be config settings and not trigger additional builds.

if you could try that please let me knew of see any difference in build time and logs.

@bencohen4
Copy link

@dthyresson here is my vercel.json config:

{
  "functions": {
    "api/src/functions/*": {
      "maxDuration": 60,
      "runtime": "@vercel/[email protected]"
    }
  }
}

Removing the runtime failed the deployment with the error "Error: The pattern "api/src/functions/*" defined in functionsdoesn't match any Serverless Functions inside theapi directory."

@dthyresson
Copy link
Contributor

Removing the runtime

Thanks for trying- could you try it you specify a non glob path? And specify the function file directly?

@bencohen4
Copy link

Will give it a go and let you know! Thanks @dthyresson

@dthyresson
Copy link
Contributor

Will give it a go and let you know! Thanks @dthyresson

Btw a local “vc build” using the Vercel cli they said should build the same way and should reproduce

@bencohen4
Copy link

@dthyresson using this vercel.json:

{
  "functions": {
    "api/src/functions/graphql.ts": {
      "maxDuration": 60,
      "runtime": "@vercel/[email protected]"
    }
  }
}

Yielded a build that took 2x as long as usual - because the steps were indeed duplicated - and the resulting Vercel deployment is still maxing out at 15 seconds, not 60 like my vercel.json implies

@dthyresson
Copy link
Contributor

@dthyresson using this vercel.json:

{
  "functions": {
    "api/src/functions/graphql.ts": {
      "maxDuration": 60,
    }
  }
}

Sorry. I may not have been clear ^^* we wanted to try without the runtime value.

@bencohen4
Copy link

@dthyresson using this vercel.json:

{

"functions": {

"api/src/functions/graphql.ts": {
  "maxDuration": 60,
}

}

}

Sorry. I may not have been clear ^^* we wanted to try without the runtime value.

@dthyresson I tried this earlier. Sorry for not being clear - Removing the runtime failed the deployment with the error "Error: The pattern "api/src/functions/*" defined in functionsdoesn't match any Serverless Functions inside theapi directory."

@dthyresson
Copy link
Contributor

dthyresson commented Jun 28, 2024

Hello @bencohen4 and @DrakenKor happy to finally give you both some promising news.

Having spoken to Vercel, they have opened an internal issue to fix this.

They have suggested to support configuring the function in the function code itself rather than the vercel.jsonl For example:

import type { APIGatewayEvent, Context } from 'aws-lambda'

import { logger } from 'src/lib/logger'

export const config = {
  maxDuration: 30,
}

export const handler = async (event: APIGatewayEvent, _context: Context) => {
  logger.info(`${event.httpMethod} ${event.path}: tester1 function`)

  return {
    statusCode: 200,
    headers: {
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      data: 'tester1 function',
    }),
  }
}

I'll update here when I get word on a release fix.

And just to let know, yes -- because of the way Vercel's Redwood builder worked, the entire app could recursively build on build n time per function config.

This behavior can be seen in logs of simply via a vercel build in your local project.

Hope to have good new soon.

BTW

I like this in function config as it:

  • is nice for functions used with Inngest to see and match and timeout durations
  • makes it easier if use custom templates and add that section
  • could be a pattern to follow for other jobs when redwood has a job runner.

@dthyresson dthyresson self-assigned this Jun 28, 2024
@dthyresson dthyresson added bug/repro-available A reproduction exists and needs to be confirmed bug/confirmed We have confirmed this is a bug and removed bug/needs-info More information is needed for reproduction labels Jun 28, 2024
@bencohen4
Copy link

bencohen4 commented Jun 28, 2024

Thank you @dthyresson!!
Just to confirm - the export const config = {} suggestion is not something that would be available to us without an update from Redwood, right? As we are blocked by the createGraphQLHandler function's setup. And also Vercel does not support this yet either.

I agree that defining the config in the function is likely much easier than defining it in json files - less room for errors

@dthyresson
Copy link
Contributor

dthyresson commented Jun 28, 2024

suggestion is not something that would be available to us without an update from Redwood, right?

Actually, it's an update necessary to the Vercel builder that handles the Redwood framework here: https://github.com/vercel/vercel/blob/main/packages/redwood/package.json

@bencohen4
Copy link

suggestion is not something that would be available to us without an update from Redwood, right?

Actually, it's an update necessary to the Vercel builder that handles the Redwood framework here: https://github.com/vercel/vercel/blob/main/packages/redwood/package.json

Got it. So we are now waiting on Vercel to make a code change to https://github.com/vercel/vercel/blob/main/packages/redwood/package.json then?

@dthyresson
Copy link
Contributor

we are now waiting

Once they tell me it's fixed and they released, I'll let you know here -- after I confirm and also update the RedwoodJS docs.

@bencohen4
Copy link

we are now waiting

Once they tell me it's fixed and they released, I'll let you know here -- after I confirm and also update the RedwoodJS docs.

thanks!!

@DrakenKor
Copy link

Thanks, this'll mean I can start using Redwood on Vercel again.

@dthyresson
Copy link
Contributor

Have tested fix shown here vercel/vercel#11776 and looking good. Just will have to wait for that to get approved, released and published.

image image

via

export const config = {
  maxDuration: 30,
  memory: 512,
}
``` in the function etc.

@bencohen4
Copy link

Have tested fix shown here vercel/vercel#11776 and looking good. Just will have to wait for that to get approved, released and published.

image image

via

export const config = {

  maxDuration: 30,

  memory: 512,

}

``` in the function etc.

Omg @dthyresson thank you!!! Can't wait!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/confirmed We have confirmed this is a bug bug/repro-available A reproduction exists and needs to be confirmed topic/deployment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants