-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
🐛 [Sessions] pq: invalid byte sequence for encoding "UTF8": 0xff #1258
Comments
Your report is very unusual, usually you create an issie first when you are sure and can give others the possibility to work on the bug. Please add a reproducible example and/or information about the bug, otherwise this offers no possibility to do anything here and we have to close it. |
As I mentioned, we are closing the ticket, if you have a reproducible example and an error message, feel free to open it again |
Okay, the server started up after I deleted the table with the sessions, which is created by Fiber middleware package that uses Postgres. But now a new error: |
Okay I was finally able to make a somewhat reproducible example! How to Code snippet: package main
import (
"fmt"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/session"
"github.com/gofiber/storage/postgres"
)
func main() {
store := session.New(session.Config{
Storage: postgres.New(postgres.Config{
Host: "localhost",
Username: "postgres",
Password: "password",
Database: "postgres",
}),
})
app := fiber.New()
app.Get("/set", func(c *fiber.Ctx) error {
sess, err := store.Get(c)
if err != nil {
panic(err)
}
sess.Set("key", "val")
if err := sess.Save(); err != nil {
panic(err)
}
return c.Status(fiber.StatusOK).SendString("ok")
})
app.Listen(":3000")
} Log:
go.mod:
|
btw can't reopen the Issue myself, @ReneWerner87 |
I've ran your code with my database credentials and I got the |
Made a new db, ran the same code and I got the same error. Also tried another machine -- Windows + Postgres, I got the same result. I wonder what might be different between our configurations that we get different results 🤔 I'm creating a new db like this: CREATE DATABASE fiber_utf8
WITH
OWNER = postgres
ENCODING = 'UTF8'
CONNECTION LIMIT = -1; Running |
Tried renting a VPS. Took Debian 10.9.0, installed Postgres, then Golang and tried to use my code. Got the same error. Go: |
Thanks for the info, will use a VPS to try to solve this issue tomorrow. |
Thats because you try to store some blob data in TEXT column. Use BLOB column type and remove cast to string in |
oh, you are right https://stackoverflow.com/questions/53251572/golang-postgres-storing-gob-data hmm, we should use a blob type in our storages func (s *Storage) Set(key string, val []byte, exp time.Duration) error { since we take bytes everywhere and don't know exactly if that includes utf8 we should try to use a binary/blob/byte type everywhere @hi019 could you create a PR for this change |
Nice find @puuuuh . I'll make a PR. |
Fiber version
Fiber v2.7.1
Postgres version
PostgreSQL 13.2
Issue description
For some reason, when I try to save data to middleware, there is an error related to UTF8.
Code snippet
The text was updated successfully, but these errors were encountered: