jfischoff / tmp-postgres

Create temporary postgres instances
BSD 3-Clause "New" or "Revised" License
53 stars 17 forks source link

Could not remove pg_stat - unsatisfied constraints (Directory not empty) #251

Open ocharles opened 4 years ago

ocharles commented 4 years ago

I have been happily using tmp-postgres locally, but on CI I got:

Exception: /tmp/tmp-postgres-data-4de8de8b7e43c151/pg_stat: removeDirectoryRecursive:removeContentsRecursive:removePathRecursive:removeContentsRecursive:removeDirectory: unsatisfied constraints (Directory not empty)

I've never seen this before, any idea what could have happened?

jfischoff commented 4 years ago

ah crap.

This is a bug I'm really struggling to kill.

I think that as removeDirectoryRecursive is running new files are being added to the directory.

This is the silly hack I have left in.

https://github.com/jfischoff/tmp-postgres/blob/master/src/Database/Postgres/Temp/Internal/Config.hs#L393

The other thing I have tried is rename folder before removing but that also did not work.

I guess I should try the idea I had of locking the directories ... but I am not really sure what I was thinking because I would lock in the same process (I see now ... it is postgres that is writing into the folder so it would be a different process).

I could also just try deleting over and over again for some amount of time.

ocharles commented 4 years ago

Ah, you have experienced this too then?

jfischoff commented 4 years ago

Not recently but yes. I was pretty sure I had not solved it.

ocharles commented 3 years ago

We're hitting this a lot at the moment, so I'm doing some investigation into this. Some findings:

I think my sandboxing stuff is just luck that causes the exception to happen less frequently.

I suggest that #215 is reverted, or least configurable. I'll live with an 8ms penalty if tests actually work reliably. Also, this time is spent per test, and we run tests in parallel anyway

jfischoff commented 3 years ago

Thanks @ocharles. I think you are probably right and reverting #215 is the problem. I'll revert it.

the-dr-lazy commented 3 years ago

As a temporary hack for anyone who have same issue:

Just catch the close action.

If there is a better solution, I'd be happy to see.

ocharles commented 3 years ago

The better solution is to just revert b90ed91

ocharles commented 3 years ago

@jfischoff Do you still plan to revert the above mentioned commit? We haven't had any more problems since we reverted it (we've been running https://github.com/circuithub/tmp-postgres since my last comment)

codygman commented 3 years ago

@jfischoff My team is also affected by this, it looks like our fix will be a temporary fork of tmp-postgres reverting b90ed91 since @ocharles said it's been working for some time.

This error started showing up for us seemingly out of nowhere.

ocharles commented 2 years ago

@jfischoff Polite ping. I still think reverting #215 is worth doing.

jfischoff commented 2 years ago

@ocharles I haven't had time to work on this project recently, but I should have time this week. I'll take a look. Thanks for the ping.

parsonsmatt commented 4 months ago

I just received our first report on this. Is there anything I can do to help diagnose or get the #215 revert moving along?