UND_ERR_HEADERS_TIMEOUT error when trying to partition a large PDF

Open
#162 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
typescript
Domain
api

Research direction

Start with utils/file-to-md.ts and the POST handler at app/api/files/route.ts, then reproduce the failure with the reported 6.3 MB PDF. Trace the partition request and compare it with a smaller PDF that succeeds. Done means large PDFs no longer fail with UND_ERR_HEADERS_TIMEOUT, with the behavior verified against both sizes.

Written by the indexing model from the issue text.

Description

When trying to partition a 6.3mb PDF using the Javascript API, a "UND_ERR_HEADERS_TIMEOUT" error is thrown:

api Error [ConnectionError]: Unable to make request: TypeError: fetch failed
api     at async convertFileToMarkdown (utils/file-to-md.ts:13:35)
api     at async POST$1 (webpack-internal:/(rsc)/app/api/files/app/api/files/route.ts:38:36)
api   11 | export async function convertFileToMarkdown(file: File) {
api   12 |   try {
api > 13 |     const res: PartitionResponse = await unstructuredClient.general.partition({
api      |                                   ^
api   14 |       partitionParameters: {
api   15 |         files: {
api   16 |           content: file, {
api   [cause]: TypeError: fetch failed
api       at async convertFileToMarkdown (utils/file-to-md.ts:13:35)
api       at async POST$1 (webpack-internal:/(rsc)/app/api/files/app/api/files/route.ts:38:36)
api     11 | export async function convertFileToMarkdown(file: File) {
api     12 |   try {
api   > 13 |     const res: PartitionResponse = await unstructuredClient.general.partition({
api        |                                   ^
api     14 |       partitionParameters: {
api     15 |         files: {
api     16 |           content: file, {
api     [cause]: [Error [HeadersTimeoutError]: Headers Timeout Error] {
api       code: 'UND_ERR_HEADERS_TIMEOUT'
api     }
api   }
api }
api {
api   markdown: undefined,
api   error: 'Unable to make request: TypeError: fetch failed'
api }

Smaller PDFs work fine. Large PDFs fail. Letting the API run indefinitely, the timeout can take approximately a half hour or so until the error is finally throw, which leads me to believe the file is hung up in partitioning inside of Unstructured.io's API.

Dominant language
TypeScript
Stars
63
Forks
16
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Unstructured-IO/unstructured-js-client

All issues in Unstructured-IO/unstructured-js-client

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.