postalserver / postalserver/postal

Mysql2::Error: Data too long for column 'user_agent'

Open
#3,015 3 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Ruby
Stars
16.8k
Forks
1.3k
Avg merge
13d 7h
Merged PRs (30d)
2

Description

## Describe the bug

Occasional database error from HTTP requests that have a long user-agent header.

## To Reproduce

curl 'https://domain/{server_id}/{email_tracking_id}' -A "Mozilla/5.0 (Linux; Android 13; Pixel 4a (5G) Build/TQ2A.230505.002; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/112.0.5615.136 Mobile Safari/537.36 GoogleApp/14.16.27.29.arm64 AppEngine-Google; (+http://code.google.com/appengine; appid: s~...................)"

an observe that a 500 is returned.

## Expected behaviour

No errors to be raised, and long user agents either to be stored in the db correctly or truncated if they are excessively long.

## Additional information/context

Stack trace:
```
Mysql2::Error: Data too long for column 'user_agent' at row 1 (Mysql2::Error)
from mysql2 (0.5.6) lib/mysql2/client.rb:151:in `_query'
from mysql2 (0.5.6) lib/mysql2/client.rb:151:in `block in query'
from mysql2 (0.5.6) lib/mysql2/client.rb:150:in `handle_interrupt'
from mysql2 (0.5.6) lib/mysql2/client.rb:150:in `query'
from lib/postal/message_db/database.rb:326:in `query_on_connection'
from lib/postal/message_db/database.rb:234:in `block in insert'
from lib/postal/message_db/connection_pool.rb:20:in `use'
from lib/postal/message_db/database.rb:345:in `with_mysql'
from lib/postal/message_db/database.rb:233:in `insert'
from lib/tracking_middleware.rb:89:in `dispatch_redirect_request'
from lib/tracking_middleware.rb:26:in `call'
from secure_headers (6.5.0) lib/secure_headers/middleware.rb:11:in `call'
from railties (7.0.8.1) lib/rails/engine.rb:530:in `call'
from puma (6.4.2) lib/puma/commonlogger.rb:47:in `call'
from puma (6.4.2) lib/puma/configuration.rb:272:in `call'
from puma (6.4.2) lib/puma/request.rb:100:in `block in handle_request'
from puma (6.4.2) lib/puma/thread_pool.rb:378:in `with_force_shutdown'
from puma (6.4.2) lib/puma/request.rb:99:in `handle_request'
from puma (6.4.2) lib/puma/server.rb:464:in `process_client'
from puma (6.4.2) lib/puma/server.rb:245:in `block in run'
from puma (6.4.2) lib/puma/thread_pool.rb:155:in `block in spawn_thread'
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.