Error while deleting Mattermost User through API

We are trying to delete a user from Mattermost server through API,

curl --location --request DELETE 'https://xxxxxx/api/v4/users/USERID?permanent=true’
–header 'Authorization: Bearer TOKEN


We were getting below error

"id": "app.post.permanent_delete_by_user.app_error", "message": "Unable to select the posts to delete for the user.", "detailed_error": "MError:\nfailed to fetch Posts with userId=**TOKEN**: context deadline exceeded\ndriver: bad connection\n2 errors total.\n", "request_id": "qo1hxxcjopydzfbx4zw7ind85h", "status_code": 500

### **Mattermost Team Edition**


Mattermost Version: 7.7.1

Database Schema Version: 100

Database: postgres

Hi @praseeb ,

the message context deadline exceeded usually indicates, that the SQL query was running too long and has therefore been intercepted.
It seems as if this user account has quite a lot of posts and therefore the cleanup process might take a while.
You could try to increase the SqlSettings.QueryTimeout value in your server’s config.json (I think the change requires a server restart then) and see if that helps.
Did you track the time that elapses when you start the query until you receive the HTTP 500? If it’s near to the current QueryTimeout setting, this should be a solid guess then.

@agriesser Please find the below in our config.json

    "SqlSettings": {
        "DriverName": "postgres",
        "DataSource": "postgres://username:password@endpointurl:5432/dbname?sslmode=disable\u0026connect_timeout=10",
        "DataSourceReplicas": [],
        "DataSourceSearchReplicas": [],
        "MaxIdleConns": 20,
        "ConnMaxLifetimeMilliseconds": 3600000,
        "ConnMaxIdleTimeMilliseconds": 300000,
        "MaxOpenConns": 300,
        "Trace": false,
        "AtRestEncryptKey": "ENCRYPTKEY",
        "QueryTimeout": 30,
        "DisableDatabaseSearch": false,
        "MigrationsStatementTimeoutSeconds": 100000,
        "ReplicaLagSettings": []

Can you please suggest the idle QueryTimeout which we can set.

@agriesser please find the below config.json values

    "SqlSettings": {
        "DriverName": "postgres",
        "DataSource": "postgres://username:password@endpointurl:5432/dbname?sslmode=disable\u0026connect_timeout=10",
        "DataSourceReplicas": [],
        "DataSourceSearchReplicas": [],
        "MaxIdleConns": 20,
        "ConnMaxLifetimeMilliseconds": 3600000,
        "ConnMaxIdleTimeMilliseconds": 300000,
        "MaxOpenConns": 300,
        "Trace": false,
        "AtRestEncryptKey": "ENCRYPTYKEY",
        "QueryTimeout": 30,
        "DisableDatabaseSearch": false,
        "MigrationsStatementTimeoutSeconds": 100000,
        "ReplicaLagSettings": []

Kindly suggest us the Idle value to update in QueryTimeout

Hi @praseeb ,

hard to tell since I don’t know how long the query would run on your system, but set it to 180 for testing purposes and check again if that fixes the problem.
Increasing the timeout doesn’t really hurt if it’s done in a controlled environment.

@agriesser Thanks, it worked for us now :slight_smile:

Awesome, thanks for reporting back - glad to hear you’re up and running now :slight_smile: