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

Using knowledge API from within Dify as a custom tool fails or gives 524 error from cloudflare #12276

Closed
5 tasks done
tipani86 opened this issue Jan 1, 2025 · 5 comments
Closed
5 tasks done
Labels
🐞 bug Something isn't working cloud When the version is cloud and it is a bug report

Comments

@tipani86
Copy link

tipani86 commented Jan 1, 2025

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

0.14.2

Cloud or Self Hosted

Cloud

Steps to reproduce

(Probably unrelated but I want to say that we are a paid PRO SaaS user)

  1. Set up custom tool in Dify using Knowledge API documentation (mostly about chunk retrieval endpoint)
  2. Add the custom tool into a Dify chatflow or workflow
  3. Let the flow query the tool using a dataset ID and query string

✔️ Expected Behavior

Successful retrieval of chunks from the dataset

❌ Actual Behavior

Cross-checked two behaviors:

  1. From within Dify flow, using custom tool to call the API, will lead to one of the two errors: "Reached maximum retries..." or a Cloudflare 524 timeout.
  2. Calling the endpoint from outside (for example using Postman from own computer), everything is fine.

Note: The behavior for number 1 also worked in the past but stopped working sometime during today (Jan 1)

You can see the comparison of two behaviors below:

image

Also, the full 524 error text is attached below:

Failed to invoke tool: Request failed with status code 524 and <!DOCTYPE html> <!--[if lt IE 7]> <html class="no-js ie6 oldie" lang="en-US"> <![endif]--> <!--[if IE 7]> <html class="no-js ie7 oldie" lang="en-US"> <![endif]--> <!--[if IE 8]> <html class="no-js ie8 oldie" lang="en-US"> <![endif]--> <!--[if gt IE 8]><!--> <html class="no-js" lang="en-US"> <!--<![endif]--> <head> <title>api.dify.ai | 524: A timeout occurred</title> <meta charset="UTF-8" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta http-equiv="X-UA-Compatible" content="IE=Edge" /> <meta name="robots" content="noindex, nofollow" /> <meta name="viewport" content="width=device-width,initial-scale=1" /> <link rel="stylesheet" id="cf_styles-css" href="/cdn-cgi/styles/main.css" /> </head> <body> <div id="cf-wrapper"> <div id="cf-error-details" class="p-0"> <header class="mx-auto pt-10 lg:pt-6 lg:px-8 w-240 lg:w-full mb-8"> <h1 class="inline-block sm:block sm:mb-2 font-light text-60 lg:text-4xl text-black-dark leading-tight mr-2"> <span class="inline-block">A timeout occurred</span> <span class="code-label">Error code 524</span> </h1> <div> Visit <a href="https://www.cloudflare.com/5xx-error-landing?utm_source=errorcode_524&utm_campaign=api.dify.ai" target="_blank" rel="noopener noreferrer">cloudflare.com</a> for more information. </div> <div class="mt-3">2025-01-01 08:45:23 UTC</div> </header> <div class="my-8 bg-gradient-gray"> <div class="w-240 lg:w-full mx-auto"> <div class="clearfix md:px-8"> <div id="cf-browser-status" class=" relative w-1/3 md:w-full py-15 md:p-0 md:py-8 md:text-left md:border-solid md:border-0 md:border-b md:border-gray-400 overflow-hidden float-left md:float-none text-center"> <div class="relative mb-10 md:m-0"> <span class="cf-icon-browser block md:hidden h-20 bg-center bg-no-repeat"></span> <span class="cf-icon-ok w-12 h-12 absolute left-1/2 md:left-auto md:right-0 md:top-0 -ml-6 -bottom-4"></span> </div> <span class="md:block w-full truncate">You</span> <h3 class="md:inline-block mt-3 md:mt-0 text-2xl text-gray-600 font-light leading-1.3"> Browser </h3> <span class="leading-1.3 text-2xl text-green-success">Working</span> </div> <div id="cf-cloudflare-status" class=" relative w-1/3 md:w-full py-15 md:p-0 md:py-8 md:text-left md:border-solid md:border-0 md:border-b md:border-gray-400 overflow-hidden float-left md:float-none text-center"> <div class="relative mb-10 md:m-0"> <a href="https://www.cloudflare.com/5xx-error-landing?utm_source=errorcode_524&utm_campaign=api.dify.ai" target="_blank" rel="noopener noreferrer"> <span class="cf-icon-cloud block md:hidden h-20 bg-center bg-no-repeat"></span> <span class="cf-icon-ok w-12 h-12 absolute left-1/2 md:left-auto md:right-0 md:top-0 -ml-6 -bottom-4"></span> </a> </div> <span class="md:block w-full truncate">Ashburn</span> <h3 class="md:inline-block mt-3 md:mt-0 text-2xl text-gray-600 font-light leading-1.3"> <a href="https://www.cloudflare.com/5xx-error-landing?utm_source=errorcode_524&utm_campaign=api.dify.ai" target="_blank" rel="noopener noreferrer"> Cloudflare </a> </h3> <span class="leading-1.3 text-2xl text-green-success">Working</span> </div> <div id="cf-host-status" class="cf-error-source relative w-1/3 md:w-full py-15 md:p-0 md:py-8 md:text-left md:border-solid md:border-0 md:border-b md:border-gray-400 overflow-hidden float-left md:float-none text-center"> <div class="relative mb-10 md:m-0"> <span class="cf-icon-server block md:hidden h-20 bg-center bg-no-repeat"></span> <span class="cf-icon-error w-12 h-12 absolute left-1/2 md:left-auto md:right-0 md:top-0 -ml-6 -bottom-4"></span> </div> <span class="md:block w-full truncate">api.dify.ai</span> <h3 class="md:inline-block mt-3 md:mt-0 text-2xl text-gray-600 font-light leading-1.3"> Host </h3> <span class="leading-1.3 text-2xl text-red-error">Error</span> </div> </div> </div> </div> <div class="w-240 lg:w-full mx-auto mb-8 lg:px-8"> <div class="clearfix"> <div class="w-1/2 md:w-full float-left pr-6 md:pb-10 md:pr-0 leading-relaxed"> <h2 class="text-3xl font-normal leading-1.3 mb-4">What happened?</h2> <p>The origin web server timed out responding to this request.</p> </div> <div class="w-1/2 md:w-full float-left leading-relaxed"> <h2 class="text-3xl font-normal leading-1.3 mb-4">What can I do?</h2> <h3 class="text-15 font-semibold mb-2">If you're a visitor of this website:</h3> <p class="mb-6">Please try again in a few minutes.</p> <h3 class="text-15 font-semibold mb-2">If you're the owner of this website:</h3> <p><span>The connection to the origin web server was made, but the origin web server timed out before responding. The likely cause is an overloaded background task, database or application, stressing the resources on your web server. To resolve, please work with your hosting provider or web development team to free up resources for your database or overloaded application.</span> <a rel="noopener noreferrer" href="https://support.cloudflare.com/hc/en-us/articles/200171926-Error-524">Additional troubleshooting information here.</a></p> </div> </div> </div> <div class="cf-error-footer cf-wrapper w-240 lg:w-full py-10 sm:py-4 sm:px-8 mx-auto text-center sm:text-left border-solid border-0 border-t border-gray-300"> <p class="text-13"> <span class="cf-footer-item sm:block sm:mb-1">Cloudflare Ray ID: <strong class="font-semibold">8fb13929fa4d0825</strong></span> <span class="cf-footer-separator sm:hidden">&bull;</span> <span id="cf-footer-item-ip" class="cf-footer-item hidden sm:block sm:mb-1"> Your IP: <button type="button" id="cf-footer-ip-reveal" class="cf-footer-ip-reveal-btn">Click to reveal</button> <span class="hidden" id="cf-footer-ip">3.214.24.53</span> <span class="cf-footer-separator sm:hidden">&bull;</span> </span> <span class="cf-footer-item sm:block sm:mb-1"><span>Performance &amp; security by</span> <a rel="noopener noreferrer" href="https://www.cloudflare.com/5xx-error-landing?utm_source=errorcode_524&utm_campaign=api.dify.ai" id="brand_link" target="_blank">Cloudflare</a></span> </p> <script>(function(){function d(){var b=a.getElementById("cf-footer-item-ip"),c=a.getElementById("cf-footer-ip-reveal");b&&"classList"in b&&(b.classList.remove("hidden"),c.addEventListener("click",function(){c.classList.add("hidden");a.getElementById("cf-footer-ip").classList.remove("hidden")}))}var a=document;document.addEventListener&&a.addEventListener("DOMContentLoaded",d)})();</script> </div><!-- /.error-footer --> </div> </div> </body> </html> 
Copy link

dosubot bot commented Jan 1, 2025

The issue you're experiencing with the Knowledge API in Dify, resulting in a Cloudflare 524 error, could be related to timeout settings. The default timeout for API requests in Dify is controlled by the GUNICORN_TIMEOUT configuration, which is set to 200 seconds by default. This can be increased to 360 seconds to accommodate longer Server-Sent Events (SSE) connections [1].

Additionally, the TEXT_GENERATION_TIMEOUT_MS setting, which defaults to 60 seconds, might also be relevant if your requests involve text generation or similar processes [1].

Since the issue occurs when using the API from within Dify but not when using external tools like Postman, it suggests that the internal timeout settings or retry mechanisms might be causing the problem. Adjusting these timeout settings could help resolve the issue.

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other

@dosubot dosubot bot added cloud When the version is cloud and it is a bug report 🐞 bug Something isn't working labels Jan 1, 2025
@tipani86
Copy link
Author

tipani86 commented Jan 1, 2025

Additional explanation about the rationale, since you might be asking "why do we need to call knowledge API using a custom tool instead of using the built-in knowledge tools provided by the Dify UI"?

Answer: We need to be able to dynamically search from multiple different dataset IDs during runtime, so when we build the chatflow or workflow, we actually don't know which datasets to connect to. During runtime, we will pass the dataset ID as input variable which will be fed into the tool as dataset_id parameter for the API.

@tipani86
Copy link
Author

tipani86 commented Jan 2, 2025

I can report that the service returned to normal yesterday after several hours of being offline (from Dify SaaS servers perspective, at least). Will let you know if there are further disruptions.

@crazywoola
Copy link
Member

crazywoola commented Jan 3, 2025

We have some network issues last week from time to time. We have added more pods to handle more requests.
Sorry for the inconvenience. :)
For paid users, you can use the email support in top right corner. Actually we have several requests about the dynamic datasets. And we are adding more functionalities to RAG 2.0 in these days.

@tipani86
Copy link
Author

tipani86 commented Jan 3, 2025

We have some network issues last week from time to time. We have added more pods to handle more requests. Sorry for the inconvenience. :) For paid users, you can use the email support in top right corner. Actually we have several requests about the dynamic datasets. And we are adding more functionalities to RAG 2.0 in these days.

Thanks for clarifying the issue! And as you can see, we already figured out a way to workaround a dynamic dataset solution with the custom tool trick. But cool if you start offering the support officially soon also.

Edit: Now I feel silly as I JUST discovered HTTP request node which makes it even simpler compared to tool use. No need to compose an OpenAPI definition. Just enter all the parameters manually haha

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working cloud When the version is cloud and it is a bug report
Projects
None yet
Development

No branches or pull requests

2 participants