Comments (4)
I tried to reproduce the issue using docker-compose and couldn't reproduce it. So I tried many other things, added another parts of the original program until it finally resurfaced.
I'm sorry, but the underlying issue was in my misuse of destructor, which, in release mode, is called immediately and it closes the connection.
I'm using a connection handling class, which calls @connection = DB.open
in constructor and @connection.close
in its destructor.
I'm using this approach for 2 years now, so I don and it only started crashing in recent days, so I thought it was caused by adding more and more queries. Now, when I know the real cause, I also remembered that I moved the scope of the connection holding variable from class to method, which crystal can now optimize away completely. When it was initialized as part of the instance, it was properly destroyed after the parent class was destroyed.
See https://github.com/daliborfilus/crystal-pg-issue-230/blob/master/src/main.cr#L13 if you are interested.
(You can try running docker-compose up --build
if you have docker installed. Let postgres start first though.)
On line https://github.com/daliborfilus/crystal-pg-issue-230/blob/master/src/main.cr#L54 handle is initialized, but immediately destroyed. What I still don't understand is how adding debug output helps with it. That's kind of a mystery. But oh well.
Sorry for the trouble and for taking your time.
from crystal-pg.
Tried to make the queries smaller - that did not help. It looks like it's really caused by just too many queries in rapid succession , without any break like logging, etc.
Just now I've tried adding small log message above each query and that doesn't help for some reason. It looks like the "puts" operation in between must take longer.
queries_num = 0
queries.each do |query_str|
queries_num += 1
Log.info { "Running query no. #{queries_num}" }
affected += tx.connection.exec(query_str).rows_affected
end
Log.info { "Affected rows total: #{affected}" }
result in --release
mode with this:
2021-06-20T20:40:55.804905Z INFO - seed: Running seed queries
2021-06-20T20:40:55.806832Z INFO - seed: Running query no. 1
Unhandled exception: (DB::ConnectionLost)
from lib/pg/src/pg/statement.cr:11:5 in 'perform_query'
from lib/pg/src/pg/statement.cr:35:14 in 'exec'
from src/gen/actions/seed.cr:46:23 in 'run'
from src/main.cr:7:1 in '__crystal_main'
from /snap/crystal/652/share/crystal/src/crystal/main.cr:110:5 in 'main'
from __libc_start_main
from _start
from ???
So it crashes on the query (!). It always crashes, it doesn't allow for even one query to run, ever.
But with debug logging enabled OR in non-release mode it succeds.
from crystal-pg.
from crystal-pg.
It's great you figured out the cause and put it here. Hopefully if anyone else does the same thing, they’ll be able to find it. So thanks for reporting it, even if it wasn't anything in the library itself :)
from crystal-pg.
Related Issues (20)
- shards update/install/build failing at the crystal-pg step HOT 2
- What versions are supported? HOT 2
- Unhandled exception: cannot insert multiple commands into a prepared statement (PQ::PQError) HOT 3
- getting OverflowError:Arithmetic overflow HOT 6
- Error: no overload matches 'PG::Decoders.array_decoder' with type UUID.class HOT 1
- Connecting to unix socket with url HOT 3
- Shards update broken on Crystal 1.0 HOT 2
- Unable to connect to Cockroachdb HOT 2
- New Release 0.23.3? HOT 2
- cockroach db HOT 2
- Proper implementation of `sslmode=verify-full` HOT 2
- Unhandled exception: column "foo" does not exist (PQ::PQError) - How to insert into table without specifying all the columns HOT 1
- Time seems to drop precision when passed in as an arg using at_end_of_day HOT 5
- Tables with upcase symbols not readed HOT 2
- Error: can't cast to JSON::Any
- Add ability to automatically return `TIMESTAMPTZ`->`Time` in the Postgres session's time zone
- Exception sending query with bytea[] binary array type? HOT 2
- Support inserting `PG::Interval` instances HOT 3
- Support for fetching results in the text format
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from crystal-pg.