lobehub / lobe-chat

🤯 Lobe Chat - an open-source, modern-design AI chat framework. Supports Multi AI Providers( OpenAI / Claude 3 / Gemini / Ollama / Azure / DeepSeek), Knowledge Base (file upload / knowledge management / RAG ), Multi-Modals (Vision/TTS) and plugin system. One-click FREE deployment of your private ChatGPT/ Claude application.
https://chat-preview.lobehub.com
Other
44.12k stars 9.86k forks source link

[Bug] Docker-database depoly File Chunk Error #3819

Open Lostsite opened 1 month ago

Lostsite commented 1 month ago

📦 Environment

Docker

📌 Version

v1.15.18

💻 Operating System

Ubuntu, Other Linux

🌐 Browser

Firefox

🐛 Bug Description

Upload a file, try to chunk, filed. The file can correctly preview and download, just can't chunk.

Here is the error log (confidential information been removed, include domain name and token):

[ParseFileToChunks] error: d [TRPCClientError]: Unsupported GET-request to mutation procedure at path "file.parseFileToChunks"
    at d.from (/app/.next/server/chunks/35260.js:31:134869)
    at /app/.next/server/chunks/35260.js:31:140525
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  meta: {
    response: Response {
      status: 405,
      statusText: 'Method Not Allowed',
      headers: Headers {
        date: 'Sun, 08 Sep 2024 05:07:41 GMT',
        server: 'Apache/2.4.62 (Debian)',
        vary: 'RSC,Next-Router-State-Tree,Next-Router-Prefetch,trpc-accept',
        'content-type': 'application/json',
        'set-cookie': '__Host-authjs.csrf-token=token_value_removed; Path=/; HttpOnly; Secure; SameSite=Lax, __Secure-authjs.callback-url=https%3A%2F%2Fmy.domain.example.com; Path=/; HttpOnly; Secure; SameSite=Lax',
        'keep-alive': 'timeout=5, max=100',
        connection: 'Keep-Alive',
        'transfer-encoding': 'chunked'
      },
      body: ReadableStream { locked: true, state: 'closed', supportsBYOB: true },
      bodyUsed: true,
      ok: false,
      redirected: true,
      type: 'cors',
      url: 'https://my.domain.example.com/trpc/async/file.parseFileToChunks?batch=1'
    },
    responseJSON: [ [Object] ]
  },
  shape: {
    message: 'Unsupported GET-request to mutation procedure at path "file.parseFileToChunks"',
    code: -32005,
    data: {
      code: 'METHOD_NOT_SUPPORTED',
      httpStatus: 405,
      path: 'file.parseFileToChunks'
    }
  },
  data: {
    code: 'METHOD_NOT_SUPPORTED',
    httpStatus: 405,
    path: 'file.parseFileToChunks'
  },
  [cause]: undefined
}

📷 Recurrence Steps

Special steps during deploy: docker arguments:

docker run -it -d -p 127.0.0.1:3210:3210 --network="host" --------- (rest are same)

(Set --network="host" to connect to local pgsql)

Set nft tables to drop all traffic from outside to port 3210

table ip filter {
    chain input {
        type filter hook input priority 0; policy accept;
        iifname != "lo" tcp dport 3210 counter drop
    }
}

Set Apache httpd to do reverse proxy

<VirtualHost *:80>
    ServerName my.domain.example.com

    ProxyPreserveHost On
    ProxyPass / http://localhost:3210/
    ProxyPassReverse / http://localhost:3210/

    ErrorLog ${APACHE_LOG_DIR}/my.domain.example.com.log
    CustomLog ${APACHE_LOG_DIR}/my.domain.example.com-access.log combined
</VirtualHost>

Last use certbot to get a CA, also let it auto config the https redirect.

🚦 Expected Behavior

No response

📝 Additional Information

Server Operating System: Debian 12, with local pgsql installation.

lobehubbot commented 1 month ago

👀 @Lostsite

Thank you for raising an issue. We will investigate into the matter and get back to you as soon as possible. Please make sure you have given us as much context as possible.\ 非常感谢您提交 issue。我们会尽快调查此事,并尽快回复您。 请确保您已经提供了尽可能多的背景信息。

dosubot[bot] commented 1 month ago

Hello, @Lostsite! I'm here to help you with any bugs, questions, or contributions you have. Let's work together to solve this issue.

The error you're encountering, "Unsupported GET-request to mutation procedure at path 'file.parseFileToChunks'", indicates that a GET request is being made to a mutation endpoint, which only supports POST requests. Here are some steps to resolve this issue:

  1. Ensure Correct Request Method: Verify that the asyncParseFileToChunks method in your code is correctly using the mutate method to trigger the mutation. This should ensure that a POST request is made.

    async asyncParseFileToChunks(fileId: string, payload: JWTPayload, skipExist?: boolean) {
     const result = await this.fileModel.findById(fileId);
    
     if (!result) return;
    
     if (skipExist && result.chunkTaskId) return;
    
     const asyncTaskId = await this.asyncTaskModel.create({
       status: AsyncTaskStatus.Processing,
       type: AsyncTaskType.Chunking,
     });
    
     await this.fileModel.update(fileId, { chunkTaskId: asyncTaskId });
    
     const asyncCaller = await createAsyncServerClient(this.userId, payload);
    
     asyncCaller.file.parseFileToChunks
       .mutate({ fileId: fileId, taskId: asyncTaskId })
       .catch(async (e) => {
         console.error('[ParseFileToChunks] error:', e);
    
         await this.asyncTaskModel.update(asyncTaskId, {
           error: new AsyncTaskError(
             AsyncTaskErrorType.TaskTriggerError,
             'trigger file parse async task error. Please check your app is public available or check your proxy settings is set correctly.',
           ),
           status: AsyncTaskStatus.Error,
         });
       });
    
     return asyncTaskId;
    }
  2. Check Reverse Proxy Configuration: Ensure that your Apache reverse proxy configuration is correctly forwarding POST requests. The configuration you provided looks correct, but double-check for any potential issues.

    <VirtualHost *:80>
       ServerName my.domain.example.com
    
       ProxyPreserveHost On
       ProxyPass / http://localhost:3210/
       ProxyPassReverse / http://localhost:3210/
    
       ErrorLog ${APACHE_LOG_DIR}/my.domain.example.com.log
       CustomLog ${APACHE_LOG_DIR}/my.domain.example.com-access.log combined
    </VirtualHost>
  3. Network and Firewall Rules: Ensure that your Docker network and firewall rules are not interfering with the request methods. The nftables configuration you provided should not affect the request methods, but it's worth double-checking.

    table ip filter {
       chain input {
           type filter hook input priority 0; policy accept;
           iifname != "lo" tcp dport 3210 counter drop
       }
    }
  4. Docker Deployment Configuration: Verify that there are no specific configurations in your Docker deployment that might affect the HTTP request methods. Ensure that the network mode and port mappings are correctly set up.

    network_mode: 'service:network-service'

By following these steps, you should be able to resolve the issue and ensure that the correct request method is used for the mutation procedure [1][2].

To continue talking to Dosu, mention @dosu.

Lostsite commented 2 weeks ago

If anyone can give me a hint? I just tried to deploy the newest docker image, the same issue happens once again. Still gives message: 'Unsupported GET-request to mutation procedure at path "file.parseFileToChunks"'

If anyone had successfully performed docker deploy with reverse proxy, could anyone give me a hint about how to correctly deploy this?