-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
--detectOpenHandles prints nothing, just hangs #9473
Comments
confirmed. I saw the same message in the console, ran the command with --runInBand and --detectOpenHandles but it was left hanging same version of mac os, node 12.13.0, yarn 1.21.1, npm 6.13.6, jest 25.1.0 |
Without a repro, this is not actionable. Feel free to reopen if you can provide a minimal (= not just a project with lots of tests and config that may or may not be related to the issue) one.
|
@jeysal hello. Please check my repo - umbress. You can find all my tests and configs in there. Also you can go to pull requests tab and see there an ongoing/failed tests for my latest PR - full GitHub Actions logs is there for you to explore :) In my PC when I start
But in Github Actions message is changing to
Edit: |
Same problem here. Please reopen. |
We won't reopen this without a minimal repro. The only repo posted is not useful, since we don't have time to spend on hunting down leaks in big repos for someone, we can only take action when pointed to a concrete problem in Jest. That's why I asked for a minimal repro specifically. |
Okay, gonna try to isolate it. |
I'm seeing the same issue. I'm not asking for help debugging my code, I'm pointing out a "concrete problem in jest". In some code bases, when running jest with I have not been able to isolate a minimal reproduction, but this does not mean the issue isn't real. Unless this is expected behavior, please reopen in acknowledgement that this is clearly affecting users. |
@Prestaul don't bother. They rather ask you to provide minimal repro than actually try to investigate after a bunch of complaints. |
Adding leaked-handles package to my Jest setup code and then |
this solves it |
This fixed my issue as well, but I think it was really the runInBand option that fixed my particular issue, so it might not that helpful for this bug report. |
Curious if |
2330: Close all handles during Jest teardown r=bonomat a=luckysori _Waiting for comit-network/comit-js-sdk#176 to be merged and for those changes to be included in a release of `comit-js-sdk` before we can update the last commit in this PR to use that release instead of a local dependency created via [`yalc`](https://github.com/whitecolor/yalc) (which seems to work **much** better than `yarn link`)._ Fixes #2211. 1. Turns out Jest will hang until every timeout is cleared, so racing against a timeout that is only cleared after it resolves was not good. 2. The proper teardown of the e2e test environment is fully achieved with 3698f3a, after a lot of debugging. Unfortunately, Jest recommends this ``` Consider running Jest with `--detectOpenHandles` to troubleshoot this issue ``` when tests hang after passing, but it just [doesn't seem to do anything](jestjs/jest#9473). I tried using [`leaked-handles`](https://github.com/Raynos/leaked-handles) without success, but finally found [`wtfnode`](https://github.com/myndzi/wtfnode), which identified `bcoin` as the culprit. --- My OCD was definitely triggered with this one, as a different error got me to investigate how to get rid of `smack-my-jasmine-up`. Turns out removing it did not fix that other error, but I still see it as a win, since depending on such an obscure library is bad. --- And another bug squashed! No more ``` MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 SIGHUP listeners added to [process]. Use emitter.setMaxListeners() to increase limit ``` errors, by combining cde8e0c and 127a4a2: - shutting down the logger during teardown. - closing log files after 5 seconds of inactivity, to prevent us from reaching the limit of listeners. I believe log files can be reopened if something else needs to be logged. Co-authored-by: Lucas Soriano del Pino <[email protected]>
I've also hit this a number of times and again today, so I made a minimal repro from my most recent encounter: https://github.com/levilansing/jest-9473 I'm reasonably certain I've encountered this with timers and promises in the past, but couldn't repro just now. In this repo, I've left a connection open to redis during tests, which should obviously be mocked during tests, but demonstrates that jest does not provide any hint to what might be causing the tests to hang when using --detectOpenHandles in this case. |
Shouldn't this issue be re-opened, now that someone has provided a minimal repro? |
I'm having the same problem. Tried all suggestions here but to no avail. |
Same problem here, but I am just starting a new project. Should I check other test libraries? any suggestion? thanks |
@lmajowka @papaiatis refer to comment and install the proposed module. For me it was Redis module that was not properly closing the connection. In your environment it will show you some other leaking pipes. |
Yes, I tried that, and it didn't give me any valuable information. |
Why does the library have Of course you also can find the leaked handles manually by isolating the leaking component, but this does not change the fact that |
I am seeing these errors too (even after |
What is expected behaviour of --detectOpenHandles? The documentation says that it shall print something. But when I run JEST with this parameter, the test never finishes and there is nothing written at all when I kill the process with Ctrl-C. Am I missing something? |
I have the same issue.
Then Then
So executing This makes sense but I would rather like to know which handle of mine is still open to close it in a clean way. Edit 2020-04-23:I was able to strip down my project and reproduce the error. Have an assumption what is the reason in my code which causes the issue. Edit 2020-04-24:Registered timeouts are not detected by the jest "detectOpenHandles" option I hope it helps to find the error in Jest or Jest is intended like that then it might help users to find and fix issues on their side. |
@jeysal Hi, I can see above that two minimal repros were provided. Is it possible to reopen this? Thanks! |
This was the issue for me... I applied the workaround suggested in that issue to get jest to exit again. |
Yes, I think I am also facing a similar issue. |
@jeysal I tried to produce a small example but this doesn't happen on small projects. Nonetheless, here is a project, it just has 5-6 routes and a react-client. Just remove the |
Fixed this by doing the following (not sure if all steps are necessary but it worked): npm i -D fsevents@latest
npm dedupe
npm uninstall -D fsevents Confirm fsevents is bumped to at-least |
@track0x1 what system were you on? windows / mac / linux / something else? |
@hasezoey This was on a mac |
FWIW, I have this same issue on Linux which isn't installing |
For anyone struggling with this issue and using // src/lib/redisClient.js # whatever path you instantiate the package
export const redis = new Redis(config.REDIS_URL); import { redis } from "src/lib/redisClient";
// tests/setupTest.js
afterAll(async () => {
await redis.quit();
}); Referring from: redis/ioredis#1088 (comment) |
For anyone having troubles with tests using vue-test-utils that get stuck, don't forget to For example, I had a test that called I hope this helps someone. |
I come here to share my experience. TL;DR: in my case it was my unclosed database connections that was triggering this log... Long version: afterAll(async () => {
for (const connection of mongoose.connections) {
await connection.close();
}
}); In order to reproduce: import request from "supertest";
import app from "./app";
/**
* app:
* - an express() app instance
* - with an endpoint `/api/test` for example
* - which requires a mongoose Model with an active connection
*/
describe('description', () => {
it('description', async () => {
const req = await request(app).post("/api/test");
})
}); HTH |
The problem is not really what triggers this log, as that varies from user to user. The problem is that --detectOpenHandles makes Jest freezes instead of printing information. |
@laurent22 Indeed, I agree, just wanted to share in order to help people working around until Jest can give more info on what is locking the process. I felt that my case is a pretty common usage. |
I had a similar issue to @Jule-, but it was how I was making a connection to Mongo via mongoose. It seems like mongoose's My approach was to set up a single connection before all tests within a For example: const options = {
useNewUrlParser: true, // avoids DeprecationWarning: current URL string parser is deprecated
useCreateIndex: true, // avoids DeprecationWarning: collection.ensureIndex is deprecated.
useFindAndModify: false, // avoids DeprecationWarning: collection.findAndModify is deprecated.
useUnifiedTopology: true // avoids DeprecationWarning: current Server Discovery and Monitoring engine is deprecated
};
export const connectToDatabase = (): Promise<typeof mongoose> =>
mongoose.connect(`mongodb://localhost/${DATABASE}`, options); setupTests.ts (this works about 50% of the time unless I used import mongoose from "mongoose";
import { connectToDatabase } from "~database";
beforeAll(async () => {
await connectToDatabase();
});
afterAll(() => {
mongoose.connection.close();
}); Instead, removing the import mongoose from "mongoose";
import { connectToDatabase } from "~database";
describe("Example", () => {
beforeAll(async () => {
await connectToDatabase();
});
afterAll(async () => {
await mongoose.connection.close();
});
it("...", () => {});
}); |
@laurent22 is exactly right. This thread is not about posting workarounds, which is what this has become. Nothing against everyone sharing info. Without any official response that is actually useful, that's what happens. Given that there's clearly no intention to fix this, I guess it's time for me to unsubscribe from my own bug report. Sigh. |
|
I have experienced the same problem with a |
Using stack trace of the first one isn't suuuuper useful, but it's something pointing to redis at least 🙂
Same here As far as I can see, these are the only 2 reproductions posted, which have both been fixed (in #11429 🚀), so I'll close this one as it's suuuuper long and full of workarounds and "+1"s. One improvement I want to make is print "sorry, we found no open handles" or some such so it doesn't seems like Jest didn't react to the flag. If somebody using Jest 27 or newer (try out |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
🐛 Bug Report
When I run my test suite I get one of these 2 messages:
or
For one, I think the mention of
--runInBand
in the first message is probably not necessary. But in any case, when I start running jest with--detectOpenHandles
, I get no output, jest just hangs after finishing the tests.Expected behavior
I would expect detectOpenHandles to give me actionable output.
envinfo
The text was updated successfully, but these errors were encountered: