status
stringclasses 1
value | repo_name
stringlengths 9
24
| repo_url
stringlengths 28
43
| issue_id
int64 1
104k
| updated_files
stringlengths 8
1.76k
| title
stringlengths 4
369
| body
stringlengths 0
254k
⌀ | issue_url
stringlengths 37
56
| pull_url
stringlengths 37
54
| before_fix_sha
stringlengths 40
40
| after_fix_sha
stringlengths 40
40
| report_datetime
unknown | language
stringclasses 5
values | commit_datetime
unknown |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 2,450 | ["dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ExecutorService.java"] | [BUG] cannot complement data for one day |
cannot complement data for one day.
![image](https://user-images.githubusercontent.com/29528966/79549206-443f4380-80c9-11ea-9ec9-678b65095969.png)
| https://github.com/apache/dolphinscheduler/issues/2450 | https://github.com/apache/dolphinscheduler/pull/2493 | 2f5427ca33b8e929d58412699699141191c640b4 | b5fdce4164385f1df2ddb25c9441b50ea28ce681 | "2020-04-17T08:35:59Z" | java | "2020-04-23T02:23:32Z" |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 2,442 | ["dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ResourcesService.java", "dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ResourcesServiceTest.java"] | [BUG] update the directory of resource is error |
update the directory occasionally appears the resource file does't exist, and the actual update directory is successful
![image](https://user-images.githubusercontent.com/55787491/79429815-9feecb80-7ffa-11ea-9c00-41e88eed05e9.png)
![image](https://user-images.githubusercontent.com/55787491/79429960-cd3b7980-7ffa-11ea-958e-32cefebfeffe.png)
![image](https://user-images.githubusercontent.com/55787491/79430009-e17f7680-7ffa-11ea-91ea-87c9d91237b1.png)
**Which version of Dolphin Scheduler:**
-[dev]
| https://github.com/apache/dolphinscheduler/issues/2442 | https://github.com/apache/dolphinscheduler/pull/2524 | c50ad1240c4789403e9518c855c0217fc9030b5b | e6dec8d2a7a6d39280675d225ec818e0cc7012be | "2020-04-16T08:01:56Z" | java | "2020-04-27T06:16:21Z" |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 2,350 | ["dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/zk/ZKMasterClient.java", "dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/zk/AbstractZKClient.java"] | [BUG] master fault tolerance error | 1. Start one master1 and two workers
2. Task setting timing, executed once every 1 minute, online timing
3. There are 3 workflow instances running on the master1 service, and the task shell_task_1 of the workflow instance is also in the "running" state.
4. Start the master2 service, the host of the workflow instance changes from master1 to master2, and the task shell_task_1 also starts fault-tolerant processing, as shown in the following figure, and finally shell_task_1 is executed 3 times:
===============================================
1.启动一台master1 , 2台worker
2.任务设置定时,1分钟执行一次,上线定时
3.有3个工作流实例在master1服务上运行,其中工作流实例的任务shell_task_1也处于“正在运行”状态
4.启动master2服务,工作流实例的host从master1变为master2,任务shell_task_1也开始容错处理,如下图所示,最终shell_task_1被执行3次:
===============================================
![image](https://user-images.githubusercontent.com/55787491/78106433-f4545180-7425-11ea-8bc6-ebcf916236f8.png)
![image](https://user-images.githubusercontent.com/55787491/78106449-fe765000-7425-11ea-8dd8-3c14ec90d4fb.png)
![image](https://user-images.githubusercontent.com/55787491/78106564-3d0c0a80-7426-11ea-956e-42b2b19a01cd.png)
**Which version of Dolphin Scheduler:**
-[refactor-worker]
| https://github.com/apache/dolphinscheduler/issues/2350 | https://github.com/apache/dolphinscheduler/pull/2375 | c9620ab557ec4c8d0bef1c87c93348b238a7bd8e | 785c34bc66b04dbccbd64639850dc44d67957aba | "2020-04-01T06:38:43Z" | java | "2020-04-07T08:23:31Z" |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 2,349 | ["dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/zk/ZKMasterClient.java", "dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/zk/AbstractZKClient.java"] | [BUG]Visit the worker page of the monitoring center, a null pointer occur |
![image](https://user-images.githubusercontent.com/55787491/78097549-2a3a0b80-740f-11ea-8302-5c63fa1b79dc.png)
![image](https://user-images.githubusercontent.com/55787491/78097589-3faf3580-740f-11ea-82d2-4249cef0e876.png)
**Which version of Dolphin Scheduler:**
-[refactor-worker]
| https://github.com/apache/dolphinscheduler/issues/2349 | https://github.com/apache/dolphinscheduler/pull/2375 | c9620ab557ec4c8d0bef1c87c93348b238a7bd8e | 785c34bc66b04dbccbd64639850dc44d67957aba | "2020-04-01T03:53:07Z" | java | "2020-04-07T08:23:31Z" |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 2,282 | ["dolphinscheduler-dao/src/main/resources/application.properties", "dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/task/dependent/DependentExecute.java", "dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/task/dependent/DependentTask.java", "dolphinscheduler-server/src/test/java/org/apache/dolphinscheduler/server/worker/task/dependent/DependentTaskTest.java", "dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessService.java", "pom.xml"] | this workflow is bug , I think it's a very serious problem | Is I also found a problem, it is a bug, is I have two workflow of a and b, then a workflow Riga, a1 node b work new b1 task dependent nodes, type selection, the chosen today, relying on a1, my situation is such, a workflow, I have the day before the creation of a1 run through a process, and then I run b process, theory should be run failed, but in fact was a success.I am also drunk, similarly I choose the type of b1 yesterday also can run successfully, but the first three days before the election run failed.That logo is faild | https://github.com/apache/dolphinscheduler/issues/2282 | https://github.com/apache/dolphinscheduler/pull/2329 | 949b8ef17d2b734b239ce31c997d7084868347b7 | 69e000b54214e8331ede69bdce9710b8418e960e | "2020-03-23T08:00:51Z" | java | "2020-04-02T16:16:01Z" |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 2,178 | ["dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/task/sql/SqlTask.java"] | [BUG] SqlTask kerberos authentication process | *For better global communication, please give priority to using English description, thx! *
**Describe the bug**
When the keytab is expired or deactivated, other tasks that did not require authentication also failed. Obviously there is something wrong with the kerberos authentication process and it should only do it when it is needed.
**Which version of Dolphin Scheduler:**
-[1.2.1-release]
**Requirement or improvement
- Change CommonUtils.loadKerberosConf() call scope;
| https://github.com/apache/dolphinscheduler/issues/2178 | https://github.com/apache/dolphinscheduler/pull/2321 | a851168a350e300becb3452e91871220ffa3a5fc | d4735334a1986fedd5b92d185dc6d46be93cb071 | "2020-03-14T11:25:36Z" | java | "2020-03-28T09:42:33Z" |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 2,111 | ["dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/OSUtils.java", "dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/process/ProcessImplForWin32.java", "dolphinscheduler-server/src/test/java/org/apache/dolphinscheduler/server/worker/task/shell/ShellTaskTest.java"] | [BUG] sun.misc.JavaIOFileDescriptorAccess is not portable | Current implementation relies on `sun.misc.JavaIOFileDescriptorAccess` which is only accessible on oraclejdk8.
Basically the demand is getting & setting `field` field of `FileDescriptor`, so we can directly do that with reflection.
Though, I suspect the necessity we introduce `ProcessImplForWin32`. Maybe we could have a better way to support worker server to run bat script. | https://github.com/apache/dolphinscheduler/issues/2111 | https://github.com/apache/dolphinscheduler/pull/2113 | 450a1f56fc73f088fce89a343a0b008706f2088c | 9224b49b58b756d22c75d8929108f716283282b4 | "2020-03-08T05:09:46Z" | java | "2020-03-09T11:06:41Z" |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 2,101 | ["dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessInstanceService.java", "dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionServiceImpl.java", "dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/task/conditions/ConditionsParameters.java", "dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessService.java", "dolphinscheduler-service/src/test/java/org/apache/dolphinscheduler/service/process/ProcessServiceTest.java"] | [BUG] After renaming the branch name, the name of Branch Flow does not change | 更改任务名称后,分支流转的名称还是更改前的任务名称
![image](https://user-images.githubusercontent.com/55787491/76071071-9e2ff200-5fd0-11ea-8702-e7b357d7b060.png)
**Which version of Dolphin Scheduler:**
-[1.2.0_release]
| https://github.com/apache/dolphinscheduler/issues/2101 | https://github.com/apache/dolphinscheduler/pull/4555 | cfd9db5555b3d8f9f33f25a9272c8741115a9336 | 14d49bc584685a33e2952573a0cb6e88377ab9f9 | "2020-03-06T09:35:19Z" | java | "2021-02-02T08:07:37Z" |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 1,996 | ["install.sh"] | [BUG] install.sh will happen "sh: bin/dolphinscheduler-daemon.sh: No such file or directory" when first deploy | **Describe the bug**
when I first deploy the DolphinScheduler, I find that
```
# 3,stop server
echo "3,stop server"
sh ${workDir}/script/stop-all.sh
...
# 5,scp resources
echo "5,scp resources"
sh ${workDir}/script/scp-hosts.sh
if [ $? -eq 0 ]
then
echo 'scp copy completed'
else
echo 'scp copy failed to exit'
exit -1
fi
```
**Which version of Dolphin Scheduler:**
-[1.2.0]
**how to solve**
the 3 step should change position to the 5 step, becase on the 3 step, the shell scripts not exists in the install path | https://github.com/apache/dolphinscheduler/issues/1996 | https://github.com/apache/dolphinscheduler/pull/1998 | b4f2e5f4210ce70d6ec50e68fd177ee26841fc03 | 5ecd3b30b923dc4dfa6ac846b6ac44bfb2f8e11f | "2020-02-22T12:20:33Z" | java | "2020-02-23T08:59:24Z" |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 1,968 | ["dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/dag.js", "dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/dag.vue", "dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/plugIn/jsPlumbHandle.js"] | [BUG] The task details window did not close properly. |
**Describe the bug**
The task details window did not close properly.
**To Reproduce**
1. Go to the page of the definition create or definition edit.
2. Drag to create a new task node or edit an exist node. And the task details window will be open.
3. Delete the task node or click the DataSource menu.
4. See error. The task details window still open.
**Which version of Dolphin Scheduler:**
-[dev]
**Requirement or improvement
The task details window should be close. | https://github.com/apache/dolphinscheduler/issues/1968 | https://github.com/apache/dolphinscheduler/pull/1969 | d7d7e95498cd69132660c7287052bb328a76f4ec | afd5c75cd27c9fe1a7efcafbed92bf28fc3996e5 | "2020-02-17T03:36:53Z" | java | "2020-02-17T11:09:10Z" |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 1,682 | ["dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/task/AbstractTask.java"] | [suggest] The method getcurtaskparamsclass() of class abstracttask is the same as the function of class taskparametersutils Functions can be replaced | *For better global communication, please give priority to using English description, thx! *
**Describe the bug**
The method getCurTaskParamsClass() of class AbstractTask is the same as the function of class TaskParametersUtils Functions can be replaced
**To Reproduce**
**Expected behavior**
- Delete the method getcurtaskparamsclass() of class abstracttask
**Screenshots**
If applicable, add screenshots to help explain your problem.
**Which version of Dolphin Scheduler:**
-[1.2.1-dev]
**Additional context**
**Requirement or improvement
Getcurtaskparamsclass() function of class abstracttask is replaced by taskparametersutils
| https://github.com/apache/dolphinscheduler/issues/1682 | https://github.com/apache/dolphinscheduler/pull/4262 | 3bcd3fbcd344983ed35f997bed1fea2c0cf6055d | 24864512212a94f53da32eb20dc56673f960547a | "2020-01-02T08:42:35Z" | java | "2020-12-20T13:52:52Z" |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 1,578 | [".github/workflows/ci_backend.yml", ".gitignore", "dolphinscheduler-dist/release-docs/LICENSE", "dolphinscheduler-dist/release-docs/licenses/LICENSE-lombok.txt", "dolphinscheduler-ui/package.json", "pom.xml", "tools/dependencies/check-LICENSE.sh", "tools/dependencies/known-dependencies.txt"] | [CI/CD]Checking the dependency licenses | Track the root issue #1460
Apache has strict requirements for license, so ci needs to verify license, you can refer to skywalking or other apache dependence license check flow.
skywalking link: https://github.com/apache/skywalking/blob/master/tools/dependencies/check-LICENSE.sh
if you want to contribute, you may reply "i want to implement it" | https://github.com/apache/dolphinscheduler/issues/1578 | https://github.com/apache/dolphinscheduler/pull/2552 | 6e81dd3b582546c9048b3508198dddcfbc1d3282 | 6e08b29254f3a5c340172c34a6a67e3cc8af0c48 | "2019-12-25T13:53:23Z" | java | "2020-05-02T14:19:20Z" |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 1,442 | ["dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/master/runner/MasterSchedulerThread.java"] | [BUG] code comment error |
**Describe the bug**
in this class: org.apache.dolphinscheduler.server.master.runner.MasterSchedulerThread. the line number 104, zkMasterClient.getMasterLockPath() The lock path obtained may should be /dolphinscheduler/lock/masters, but in the comment, is's /dolphinscheduler/lock/failover/master, I think it's easy to mislead people who read the source code, please check this, if it does, I can open a pr to fix it
**To Reproduce**
None
**Expected behavior**
Node
**Screenshots**
None
**Which version of Dolphin Scheduler:**
latest version
**Additional context**
None
**Requirement or improvement
None
| https://github.com/apache/dolphinscheduler/issues/1442 | https://github.com/apache/dolphinscheduler/pull/1446 | a1ded5ee041a387d56757fcdd27e39efd3a6000a | 9a3a6f5a3d5ec613b49ae1a5a947d58c351f1fc7 | "2019-12-11T03:47:22Z" | java | "2019-12-12T06:20:27Z" |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 1,441 | ["dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/Constants.java"] | [Feature] add user error when user name contains '.' | **Is your feature request related to a problem? Please describe.**
add a user when user name contains '.'
i think maybe the username regex string is error.
| https://github.com/apache/dolphinscheduler/issues/1441 | https://github.com/apache/dolphinscheduler/pull/1445 | b276ece5727bdf7cecc07bfc888f27cb75726b65 | a1ded5ee041a387d56757fcdd27e39efd3a6000a | "2019-12-11T03:07:47Z" | java | "2019-12-12T06:19:55Z" |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 1,399 | ["dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ResourcesController.java"] | [BUG] The wrong field order in logger.info | **Describe the bug**
The method onlineCreateResource in class ResourcesController,The logger.info has wrong field order with fileName and type.
**Screenshots**
<img width="1021" alt="" src="https://user-images.githubusercontent.com/3699743/70215243-0f64cc80-1778-11ea-9ec5-f6a38559b051.png">
**Which version of Dolphin Scheduler:**
- [dev-db branch]
| https://github.com/apache/dolphinscheduler/issues/1399 | https://github.com/apache/dolphinscheduler/pull/1400 | b3a0e1fd148c876d61bce92fea14528c3fb2cf45 | f134453bb838c76f046fc450ef15afccd857074e | "2019-12-05T07:59:57Z" | java | "2019-12-05T09:04:54Z" |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 1,336 | ["dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/master/runner/MasterExecThread.java"] | [BUG] [api]Dependent execution fails after task performs serial complement |
**To Reproduce**
1. A task depends on B task, the deviation range is the first 3 days
2. The serial complement of 3 days before the B task execution
3. Run workflow, dependent execution fails
![image](https://user-images.githubusercontent.com/55787491/69607569-74297400-1060-11ea-9d15-8175e79056ff.png)
**Which version of Dolphin Scheduler:**
-[1.2.0]
| https://github.com/apache/dolphinscheduler/issues/1336 | https://github.com/apache/dolphinscheduler/pull/3331 | 624f0aeab9621abbbc9584c4a3167cb1bd2dcf00 | 5f725aa28b2edbd246480a554ac7822bf07fbbfd | "2019-11-26T07:23:55Z" | java | "2020-07-29T07:37:49Z" |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 516 | ["escheduler-server/src/main/java/cn/escheduler/server/utils/LoggerUtils.java"] | The task instance of MR cannot stop in some cases | The task instance of MR cannot stop in some cases | https://github.com/apache/dolphinscheduler/issues/516 | https://github.com/apache/dolphinscheduler/pull/560 | f880a76d7a3a95d4b425a16853456025292b8c03 | d3e59773085cf287e908a789b58a14285a57da43 | "2019-07-04T04:51:57Z" | java | "2019-07-10T09:21:12Z" |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 319 | ["dolphinscheduler-ui-next/src/locales/modules/en_US.ts", "dolphinscheduler-ui-next/src/locales/modules/zh_CN.ts", "dolphinscheduler-ui-next/src/views/security/user-manage/components/user-detail-modal.tsx"] | Stand-alone fault tolerance (running, fault tolerance...)(单机容错(正在运行、容错。。。)) | https://github.com/apache/dolphinscheduler/issues/319 | https://github.com/apache/dolphinscheduler/pull/9683 | a51b710b1c8ae43d9e9bcbc386af4d81fb7e6b65 | 86bdb826dc4df912a60d1cd8bbaffc7ad2b6913f | "2019-05-21T04:41:50Z" | java | "2022-04-24T06:14:12Z" |
|
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 104 | ["dolphinscheduler-ui/src/views/datasource/list/detail.tsx", "dolphinscheduler-ui/src/views/datasource/list/use-form.ts"] | One-click deployment optimization, use the boot, target 30 minutes to get started (一键部署优化,使用上引导,目标30分钟上手) | One-click deployment optimization, use the boot, target 30 minutes to get started
---
一键部署优化,使用上引导,目标30分钟上手 | https://github.com/apache/dolphinscheduler/issues/104 | https://github.com/apache/dolphinscheduler/pull/10876 | 1edbb5e333eb91bc04002d7f15b15c8511fd7eed | 56fe11ecf9e50bdd984920a065b8ba0680e741f1 | "2019-04-22T14:32:40Z" | java | "2022-07-12T01:18:10Z" |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 15 | ["dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/K8sNamespaceController.java", "dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/K8sNamespaceService.java", "dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/K8SNamespaceServiceImpl.java", "dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/K8SNamespaceServiceTest.java"] | Missing LogParameter and RetStrInfo(缺少LogParameter和RetStrInfo) | LogViewServiceGrpc cannot find LogParameter and RetStrInfo below
---
LogViewServiceGrpc 下面找不到LogParameter和RetStrInfo | https://github.com/apache/dolphinscheduler/issues/15 | https://github.com/apache/dolphinscheduler/pull/15546 | 25810a81dc528feedd81e44f8f57469286c0e8c7 | 2f66a667ba6bed20003cfb17af3f347166e678c1 | "2019-04-04T03:44:51Z" | java | "2024-02-01T02:39:54Z" |
closed | apache/dolphinscheduler | https://github.com/apache/dolphinscheduler | 1 | ["docs/configs/docsdev.js"] | The link address is missing(链接地址缺少) | https://github.com/apache/dolphinscheduler/issues/1 | https://github.com/apache/dolphinscheduler/pull/15660 | 502b49a1cb845c04c6b754e88748d2de8ef84508 | 040ab34bafa25c5fd17f4ca172f05f55aa2ab446 | "2019-03-02T03:25:40Z" | java | "2024-03-04T08:49:22Z" |
|
closed | fastify/fastify | https://github.com/fastify/fastify | 5,279 | ["docs/Reference/Errors.md", "docs/Reference/Hooks.md", "docs/Reference/Reply.md", "lib/errors.js", "lib/reply.js", "test/internals/errors.test.js", "test/web-api.test.js"] | Return Response.body from a fetch call as a stream | ### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the bug has not already been reported
### Fastify version
4.25.2
### Plugin version
_No response_
### Node.js version
20.10
### Operating system
Windows
### Operating system version (i.e. 20.04, 11.3, 10)
11
### Description
I make a fetch call on my Fastify server and I want to return the response from that fetch call as the response of my Fastify route **as a stream**.
I thought this would work since Fastify has stream docs (https://fastify.dev/docs/latest/Reference/Reply/#streams), but it does not.
### Steps to Reproduce
Clone this github repo: [https://github.com/TJBlackman/fastify-stream-test](https://github.com/TJBlackman/fastify-stream-test)
Install dependencies and run the project:
- npm i
- npm run dev
Make requests to the API:
- GET http://localhost:3000/api/json - Works!
- GET http://localhost:3000/api/stream - Does not work :(
For the sake of completeness, here is the demo server file you could copy/paste if you want.
```js
const fastify = require("fastify")({ logger: true });
// return JSON from SWAPI - works!
fastify.get("/api/json", async (request, reply) => {
const response = await fetch("https://swapi.dev/api/people/1/");
const json = await response.json();
return reply.send(json);
});
// return stream from SWAPI - doesn't work
fastify.get("/api/stream", async (request, reply) => {
const response = await fetch("https://swapi.dev/api/people/1/");
return reply.send(response.body);
});
fastify.listen({ port: 3000 }, (err) => {
if (err) {
fastify.log.error(err);
process.exit(1);
}
});
```
### Expected Behavior
The streamed response should be the same as the JSON response. | https://github.com/fastify/fastify/issues/5279 | https://github.com/fastify/fastify/pull/5286 | bdd647d522e0d09320133eac48ddc0bc3706241f | 101ba57f894281421d902bf509adb4270473799d | "2024-01-21T23:26:20Z" | javascript | "2024-01-29T09:06:36Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 5,241 | ["CODE_OF_CONDUCT.md", "GOVERNANCE.md", "SECURITY.md"] | Drop security, governance, coc, and contributing files from this repo? | ### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the issue has not already been raised
### Issue
Rather than maintaining/updating two versions of the same document, can we drop `SECURITY.md`, `GOVERNANCE.md`, `CODE_OF_CONDUCT.md` and `CONTRIBUTING.md` from this repo so that the shared ones from [`fastify/.github`](https://github.com/fastify/.github) will be used instead?
See https://docs.github.com/en/communities/setting-up-your-project-for-healthy-contributions/creating-a-default-community-health-file | https://github.com/fastify/fastify/issues/5241 | https://github.com/fastify/fastify/pull/5268 | 62f564d965949bc123184a27a610f214f23e9a49 | bdd647d522e0d09320133eac48ddc0bc3706241f | "2023-12-28T11:16:38Z" | javascript | "2024-01-29T09:01:05Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 5,237 | ["build/build-validation.js", "docs/Reference/Server.md", "fastify.d.ts", "fastify.js", "lib/configValidator.js", "lib/route.js", "test/internals/initialConfig.test.js", "test/types/instance.test-d.ts", "test/useSemicolonDelimiter.test.js", "types/instance.d.ts"] | Cant we make this an options to be passed for useSemicolonDefault to find-my-way? | Cant we make this an options to be passed?
Solve it maybe like this?
```suggestion
options.config.useSemicolonDelimiter ?= true // To avoid a breaking change
```
+ typescript typings and documentation?
_Originally posted by @Uzlopak in https://github.com/fastify/fastify/pull/5236#discussion_r1436525251_ | https://github.com/fastify/fastify/issues/5237 | https://github.com/fastify/fastify/pull/5239 | 7264c8892a11f50fcdf7932110d17ee7ab0fd347 | cccb52e40ffef533a019fd61e117ade8fd5edd54 | "2023-12-26T17:56:43Z" | javascript | "2023-12-27T21:44:11Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 5,232 | ["docs/Guides/Ecosystem.md"] | Ecosystem.md, missing @fastify/kafka, maybe other core plugins missing too | ### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the issue has not already been raised
### Issue
Add following core plugins to the ecosystem.md file
- [ ] @fastify/express
- [ ] @fastify/kafka
- [ ] @fastify/mysql
- [ ] @fastify/passport
- [ ] @fastify/swagger-ui
- [ ] @fastify/zipkin | https://github.com/fastify/fastify/issues/5232 | https://github.com/fastify/fastify/pull/5234 | 04a4c9751e3b2501aa0a0866c512e9feb1641fb6 | 9e0faf73783de45a510969324ca4cf2284ea0a25 | "2023-12-25T19:18:32Z" | javascript | "2023-12-26T13:24:16Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 5,182 | ["docs/Reference/Hooks.md"] | possible misleading doc example in addHook about returning reply ? | ### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the issue has not already been raised
### Issue
https://fastify.dev/docs/latest/Reference/Hooks/#respond-to-a-request-from-a-hook
This code here
```
fastify.addHook('onRequest', (request, reply, done) => {
reply.send('Early response')
})
// Works with async functions too
fastify.addHook('preHandler', async (request, reply) => {
await something()
reply.send({ hello: 'world' })
return reply // mandatory, so the request is not executed further
})
```
The above docs imply that both hooks will run and returning reply is mandatory to stop processing, but in my experiments I found this to not be true.
There is also this issue that seems to back me up
https://github.com/fastify/fastify/issues/677 | https://github.com/fastify/fastify/issues/5182 | https://github.com/fastify/fastify/pull/5189 | 5d29f5c0fca40403bece7fbc84eda7cc33d9f73e | f2be4c581abc3be6d762097249209807de91700b | "2023-11-30T20:20:13Z" | javascript | "2023-12-07T22:54:33Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 5,180 | ["lib/server.js", "test/server.test.js"] | Websocket connections to secondary server prevents server from shutting down | ### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the bug has not already been reported
### Fastify version
4.24.3
### Plugin version
_No response_
### Node.js version
20.10.0
### Operating system
macOS
### Operating system version (i.e. 20.04, 11.3, 10)
14.1.1
### Description
When a websocket connection is connected to a secondary server (e.g. when we are listening to both 127.0.0.1 (secondary) and ::1 (primary) and a client connects to 127.0.0.1), we don't run the preClose operations prior to closing the secondary server. This causes the server close hook to hang indefinitely since the websocket connection is still live.
I tried debugging the issue and it appears to be related to this line (https://github.com/fastify/fastify/blob/main/lib/server.js#L178) where Fastify attaches a onClose handler that tries to close the secondary server without calling any preClose hooks unlike the primary server (https://github.com/fastify/fastify/blob/main/fastify.js#L433). This means that @fastify/websocket is unable to shutdown the sockets appropriately leading the secondary server to stall the close process indefinitely.
I was wondering if it was on @fastify/websocket side to fix, but I don't see a way they can solve this without a fix on Fastify's side since it appears the Fastify close process is hanging before any plugin can do any clean up.
### Steps to Reproduce
I created a minimal reproduction repository here: https://github.com/kingston/fastify-websocket-repro
1) Run `node index.js`
2) Open `index.html`
3) Ctrl-C the node process
### Expected Behavior
Fastify shuts down cleanly without timing out | https://github.com/fastify/fastify/issues/5180 | https://github.com/fastify/fastify/pull/5201 | 49b62f56a35f1a9a958de6aec07cee851ac2aa43 | cd84d135e663fb24fa543760a3d318e5f672449f | "2023-11-30T11:39:14Z" | javascript | "2023-12-12T19:54:28Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 5,170 | ["docs/Reference/Server.md", "fastify.js", "lib/fourOhFour.js", "lib/reqIdGenFactory.js", "lib/route.js", "lib/symbols.js", "test/genReqId.test.js", "test/types/instance.test-d.ts", "types/instance.d.ts"] | [FastifyInstance] Expose `fastify#setGenReqId` | ### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the feature has not already been requested
### 🚀 Feature Proposal
Currently, we support `genReqId` initial config when creating a `fastify` app.
This affects the root instance, and all its child afterwards.
But currently, there's no way to customize it after creation. e.g. through a `plugin`, or just through an encapsulated context.
Having `fastify#setGenReqId` (similar to the work done for `fastify#setChildLoggerFactory`) can enable different use cases at fastify at different levels.
e.g.
**Attach a function from a plugin**
Maybe you have an observability plugin standardised for your company, and it handles custom ways of inferring or creating request ids.
```js
function ObsPlugin(instance, config, done) {
// do magic
instance.setGenReqId((req) => {
// infer it or create it in a custom way
})
}
```
This will affect the parent context.
**Create different request ids based on resources**
```js
// I might want to generate one per resource
fastify.register((instance, opts, done) => {
instance.setGenReqId((req) => { /* one way for admin */})
}, { prefix: '/admin' })
fastify.register((instance, opts, done) => {
instance.setGenReqId((req) => { /* one way for common users */})
}, { prefix: '/users' })
```
I believe the benefit of the encapsulated context can be a key differentiator.
### Motivation
_No response_
### Example
_No response_ | https://github.com/fastify/fastify/issues/5170 | https://github.com/fastify/fastify/pull/5259 | 305c89de2b99f51ae322500559652197b62f75d2 | 7dc69db818c59460f5578bd5d2fe01e5eba1f788 | "2023-11-23T17:37:18Z" | javascript | "2024-01-15T07:01:36Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 5,142 | ["docs/Reference/Errors.md", "docs/Reference/Warnings.md", "test/internals/errors.test.js"] | docs: align errors and warning docs | ### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the issue has not already been raised
### Issue
Recently we added the `docs/Reference/Warnings.md` to better document all the warnings emitted by Fastify. To do that, we used tables in the format
| Code | Description | How to solve | Discussion |
| ---- | ----------- | ------------ | ---------- |
In the `docs/Reference/Errors.md` instead we list all the errors with a short description.
What do you think about aligning the style of the two pages by using a similar table for the errors? Maybe it could not be possible to write the `How to solve` column for all of the errors, but it could make the page more readable. | https://github.com/fastify/fastify/issues/5142 | https://github.com/fastify/fastify/pull/5162 | 6a337b0e02e2d28d031f409275c230e5b590dc76 | 9ab24be4621e4988e682686843664a42f4071f3d | "2023-11-04T16:56:24Z" | javascript | "2023-11-23T17:23:33Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 5,118 | ["lib/reply.js", "test/internals/reply.test.js"] | Sending a Uint8Array as a view on a larger ArrayBuffer sends the whole ArrayBuffer | ### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the bug has not already been reported
### Fastify version
4.24.3
### Plugin version
_No response_
### Node.js version
20.8.0
### Operating system
macOS
### Operating system version (i.e. 20.04, 11.3, 10)
13.5.1
### Description
I have a `RouteHandlerMethod` that sends a `Uint8Array` that is a view on part of a `ArrayBuffer`:
```js
fastify.route({
method: 'GET',
url: '/path',
handler: async (request, reply) => {
const arr = new ArrayBuffer(100)
const ui8 = new Uint8Array(arr, 0, 10)
return reply.send(ui8)
}
})
```
On the client side:
```js
const req = await fetch('/path')
const body = await req.arrayBuffer()
console.info(body.byteLength) // 100 <-- should only be 10 bytes not 100
```
This is quite bad as the array buffer offset past `10` could be random unrelated memory depending on the source of the `Uint8Array`/`ArrayBuffer`.
Node.js Buffers work as expected:
```js
fastify.route({
method: 'GET',
url: '/path',
handler: async (request, reply) => {
const arr = new ArrayBuffer(100)
const buf = Buffer.from(arr, 0, 10)
return reply.send(buf) // only sends 10 bytes
}
})
```
### Steps to Reproduce
See above.
### Expected Behavior
Only the first 10 bytes should be sent:
```js
const req = await fetch('/path')
const body = await req.arrayBuffer()
console.info(body.byteLength) // 10
``` | https://github.com/fastify/fastify/issues/5118 | https://github.com/fastify/fastify/pull/5124 | 9b8a7825dc033887d293549e40284284bf27c5a5 | bc5df037c51ee0e414654a7285342a16207293e0 | "2023-10-24T11:09:02Z" | javascript | "2023-10-28T08:32:48Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 5,113 | ["test/types/request.test-d.ts", "types/request.d.ts"] | handler doesn't exist in routerOptions | ### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the bug has not already been reported
### Fastify version
4.24.0
### Plugin version
_No response_
### Node.js version
18
### Operating system
Linux
### Operating system version (i.e. 20.04, 11.3, 10)
22
### Description
[Fastify docs](https://fastify.dev/docs/latest/Reference/Routes/#routes-options) mentioned that you can get the registered handler in onRequest hook by `request.routeOptions.hndler`, but there handler doesn't exist in the typeof `routerOptions`
```
app.addHook('onRequest', (req, res, done) => {
// Property 'handler' does not exist on type 'Readonly<RequestRouteOptions<unknown, FastifySchema>>'
console.log( req.routeOptions.handler);
done();
});
};
```
### Steps to Reproduce
.
### Expected Behavior
_No response_ | https://github.com/fastify/fastify/issues/5113 | https://github.com/fastify/fastify/pull/5136 | 396b8b95bf0f1313b9deeb387d68fdc7ffa97abe | 7aa802ed224b91ca559edec469a6b903e89a7f88 | "2023-10-22T09:08:06Z" | javascript | "2023-11-02T10:54:43Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 5,094 | ["types/instance.d.ts"] | Bump to 4.24.1 breaks build | ### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the bug has not already been reported
### Fastify version
4.24.1
### Plugin version
_No response_
### Node.js version
18.16
### Operating system
macOS
### Operating system version (i.e. 20.04, 11.3, 10)
14.0
### Description
If I bump from 4.23.2 to 4.24.1 I get following build error.
Not 100% sure if it's related, but seems to be the stuff introduced [here](https://github.com/fastify/fastify/pull/5082).
Error I get:
```
node_modules/fastify/types/instance.d.ts:146:3 - error TS1169: A computed property name in an interface must refer to an expression whose type is a literal type or a 'unique symbol' type.
146 [Symbol.asyncDispose](): Promise<undefined>;
~~~~~~~~~~~~~~~~~~~~~
node_modules/fastify/types/instance.d.ts:146:11 - error TS2339: Property 'asyncDispose' does not exist on type 'SymbolConstructor'.
146 [Symbol.asyncDispose](): Promise<undefined>;
~~~~~~~~~~~~
Found 2 errors in the same file, starting at: node_modules/fastify/types/instance.d.ts:146
```
Wondering if anyone can shed some light on it, or advise.
### Steps to Reproduce
I don't have bare minimal reproduction, but you can see the fail from bump [here](https://github.com/dailydotdev/daily-api/pull/1475).
### Expected Behavior
_No response_ | https://github.com/fastify/fastify/issues/5094 | https://github.com/fastify/fastify/pull/5096 | a9eea1cdc94259da81eb7a828e2f6e6e260dc6f2 | 24fffff11d26ed8ae0ab5ef7406e2233cc7e87b9 | "2023-10-14T08:10:11Z" | javascript | "2023-10-14T19:31:33Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 5,089 | ["lib/route.js", "test/head.test.js"] | Method 'HEAD' already declared for route - regression in 4.24.0 | ### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the bug has not already been reported
### Fastify version
4.24.0
### Plugin version
_No response_
### Node.js version
16.20
### Operating system
macOS
### Operating system version (i.e. 20.04, 11.3, 10)
latest
### Description
With the 4.24.0 release, our application no longer starts due to an error:
```
Failed to start: Error: Method 'HEAD' already declared for route '/api/v1/devices/:/editor/proxy/*' with constraints '{}'
```
Our application makes two calls to `app.route` - the first handles GET requests that *could* be a WebSocket connection, the second handles all the other methods we need to cope with.
```
app.route({
method: 'GET',
url: '/proxy/*',
...
})
app.route({
method: ['POST', 'DELETE', 'PUT', 'HEAD', 'OPTIONS'],
url: '/proxy/*',
...
})
```
With 4.24.0, this second call is triggering the error. Previous versions worked fine.
### Steps to Reproduce
I will update with a link to a repo containing as minimal reproduction as I can create tomorrow.
I wanted to get the issue recorded quickly as it appears to be a regression in 4.24.0. Looking at PRs in the release, https://github.com/fastify/fastify/pull/5078 appears very relevant.
### Expected Behavior
_No response_ | https://github.com/fastify/fastify/issues/5089 | https://github.com/fastify/fastify/pull/5090 | 04cc8c1f8a9b561cf14c7f569461bc649c16c1a1 | 91c7b448a741fe0013a139f3e69cbf52d6985fc2 | "2023-10-11T21:37:06Z" | javascript | "2023-10-12T19:04:25Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 5,068 | ["lib/route.js", "test/hooks-async.test.js"] | bug: FST_ERR_HOOK_INVALID_ASYNC_HANDLER not thrown | The following code should break:
```
const app = require("fastify")({ logger: !true });
// 🤬 DO NOT MIX ASYNC AND CALLBACK STYLE:
async function wrongHook(request, reply, done) {
console.log("preHandler");
done();
}
// FastifyError [Error]: Async function has too many arguments. Async hooks should not use the 'done' argument.
// 🚀 app.addHook("preHandler", wrongHook);
app.get(
"/",
{
preHandler: [
wrongHook, // does not throw
],
},
async (request, reply) => {
return { hello: "world" };
}
);
app.listen({ port: 3000 });
```
If I uncomment the 🚀 line, it will throw an error as expected.
We should validate the route's hook array | https://github.com/fastify/fastify/issues/5068 | https://github.com/fastify/fastify/pull/5069 | 7d97dcdf2643bcfbdcf4850867139db8189b82e2 | 16859bb0ca643b9e34be6fa4bff4a4ff9efa8289 | "2023-10-02T06:33:10Z" | javascript | "2023-10-03T14:58:04Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 5,059 | ["test/logger/instantiation.test.js", "test/logger/logger-test-utils.js", "test/logger/logging.test.js", "test/logger/options.test.js", "test/logger/request.test.js", "test/logger/response.test.js", "test/logger/tap-parallel-not-ok", "test/serial/logger.0.test.js", "test/serial/logger.1.test.js"] | Test log flaky | https://github.com/fastify/fastify/actions/runs/6289773425/attempts/1?pr=5058
The `file option` test is flaky - we should refactor a bit the `test/serial/logger.1.test.js` and spit it into smaller files as we did before.
This should reduce the flakiness | https://github.com/fastify/fastify/issues/5059 | https://github.com/fastify/fastify/pull/5064 | 14a9ccc485328134b6fe489458bccf565e0cabf1 | 7d97dcdf2643bcfbdcf4850867139db8189b82e2 | "2023-09-24T11:42:16Z" | javascript | "2023-09-29T08:53:22Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 5,049 | ["fastify.js", "test/fastify-instance.test.js", "test/hooks.on-ready.test.js"] | onReady might be executed twice | If we call `ready()` in parallel, the `onReady` hooks are triggered twice
```js
import fastify from './fastify.js'
const app = fastify()
app.addHook('onReady', async function () {
console.log('onReady')
})
await Promise.race([app.ready(), app.ready()])
await app.ready()
```
Note that this is also a problem when using `inject()` | https://github.com/fastify/fastify/issues/5049 | https://github.com/fastify/fastify/pull/5051 | b3a0e6772fe7a9bada1160a1f34549047d1d9972 | 1b588a0bfe9c395762583455a93b135e54f239e3 | "2023-09-19T10:39:50Z" | javascript | "2023-12-13T07:02:09Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 5,044 | ["docs/Reference/TypeScript.md", "types/plugin.d.ts"] | `FastifyPlugin` type deprecation notice in code JSdoc is unhelpful | ### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the bug has not already been reported
### Fastify version
3.7.x
### Plugin version
_No response_
### Node.js version
14.x
### Operating system
Linux
### Operating system version (i.e. 20.04, 11.3, 10)
22.04
### Description
The deprecation notice for `FastifyPlugin` added in https://github.com/fastify/fastify/pull/2350 is uninformative, and not easily actionable.
It mentions to see `FastifyRegister`, which makes no mention of the `FastifyPlugin` or how to replace it.
It should instead mention to use `FastifyPluginCallback`, as a synchronous analog to `FastifyPluginAsync`.
For those without the context of the deprecation of `FastifyPlugin` being replaced with the `Async` and `Callback` variants, it is not evident which plugin type to use for the case of synchronous plugin registration. The use of the `Callback` variant is not obvious if one does not anticipate making use of the `done` callback (i.e. full synchronous plugin registration).
This is made worse by the fact the `FastifyPlugin` is still referenced in the docs:
https://fastify.dev/docs/latest/Reference/TypeScript/#fastifyfastifypluginoptions-rawserver-rawrequest-requestgeneric:~:text=Open%20index.d.ts%20and%20add%20the%20following%20code%3A
Although a more informative deprecation guide is provided for the entry https://fastify.dev/docs/latest/Reference/TypeScript/#fastifyfastifypluginoptions
### Steps to Reproduce
Use `FastifyPlugin` type when defining a plugin.
### Expected Behavior
Should clearly indicate the non-deprecated replacement(s), especially for synchronous use case. | https://github.com/fastify/fastify/issues/5044 | https://github.com/fastify/fastify/pull/5070 | 78503752679d7a4f929d921cf978310136bf0dff | 96bf5a23af9e7bb9b1ac4bbde5df495ae121b4c1 | "2023-09-18T14:56:10Z" | javascript | "2023-10-11T06:57:59Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 5,040 | ["docs/Reference/Index.md", "docs/Reference/Warnings.md", "lib/warnings.js"] | docs: missing docs about warnings or deprecation warnings | ### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the issue has not already been raised
### Issue
I could not find any hints regarding deprecation warnings in the docs.
After I added https://github.com/fastify/process-warning/pull/83 to extend the documentation regarding process-warning I think we should add similar information to the docs. I mean a paragraph about how to suppress warnings (on their own risk) would be good.
Also we could make an extra page about deprecation warnings. Similar to errors.md. We should note since which version a deprecation warning was introduced, and how you can update your code to avoid the deprecation warning. Benefit is also, that you could then just copy paste that for a migration guide. So everytime we introduce a deprecation warning, we just need to make sure that the deprecations.md (name pending) also has a new entry with proper information. | https://github.com/fastify/fastify/issues/5040 | https://github.com/fastify/fastify/pull/5108 | 500c9a19ab225f266d9b6b606c7b2e40255fade0 | e4d4a213045a12de42dd7a041e75dbbea7d2c54f | "2023-09-17T08:55:08Z" | javascript | "2023-10-28T12:24:09Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 5,031 | ["docs/Reference/Request.md", "lib/warnings.js"] | request.routeOptions.config.url doesn't exist | ### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the bug has not already been reported
### Fastify version
4.23.0
### Plugin version
n/a
### Node.js version
n/a
### Operating system
Linux
### Operating system version (i.e. 20.04, 11.3, 10)
n/a
### Description
When using `request.routerPath`, Fastify emits a deprecation warning [1]:
> You are accessing the deprecated "request.routerPath" property. Use "request.routeOptions.config.url" instead. Property "req.routerPath" will be removed in `fastify@5`.
The docs also were updated to point to this, but I believe the correct property should be `request.routeOptions.url`. Not only does it make more sense since URL isn't passed in as part of the config object to a route, but if no config is passed, `request.routeOptions.config.url` won't exist.
Could someone please verify if this is correct or if I'm misunderstanding?
[1] https://github.com/fastify/fastify/blob/main/lib/warnings.js#L34
### Steps to Reproduce
```mjs
// Import the framework and instantiate it
import Fastify from 'fastify'
const fastify = Fastify({
logger: true
})
// Declare a route
fastify.get('/', async function handler (request, reply) {
console.dir(request.routeOptions); // config doesn't exist but url does
return { hello: 'world' }
})
// Run the server!
try {
await fastify.listen({ port: 3000 })
} catch (err) {
fastify.log.error(err)
process.exit(1)
}
```
### Expected Behavior
I believe the docs and deprecation warning need to be updated to point at `request.routeOptions.url`. | https://github.com/fastify/fastify/issues/5031 | https://github.com/fastify/fastify/pull/5032 | cea0536c49af460f7e6da0f76fb892576f12f2bb | 6b9b09318397b23c2feeb8c7d8699fb0c17eb48e | "2023-09-11T19:26:19Z" | javascript | "2023-09-12T07:03:15Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 5,003 | ["lib/reply.js", "test/reply-code.test.js"] | Positive `content-length` with `return Promise.resolve(null)` and `204` status code | ### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the bug has not already been reported
### Fastify version
4.22.0
### Plugin version
_No response_
### Node.js version
18.16.1
### Operating system
Linux
### Operating system version (i.e. 20.04, 11.3, 10)
6.4.11-arch2-1 (64-bit)
### Description
Hi everyone.
I'm having Postman hanging with some `204` responses.
I suspect the problem could be the positively-valued `content-length` response header. I've recreated the case without any trouble with a bare-bone Fastify instance (see `Steps to Reproduce`).
Having `reply.code(204)`:
- when I'm using an `async` (`Promise`) handler that resolves with `null` or `undefined`, the response header `content-length: 4` will be present (hanging Postman and other HTTP clients).
- when I call `reply.send()`, with or without promises, the `content-length` header is omitted from the response.
### Steps to Reproduce
```javascript
// Node.js v18.16.1
import Fastify from 'fastify' // v4.22.0
const app = Fastify({
logger: true,
})
app.route({
method: 'POST',
url: '*',
async handler(request, reply) {
reply.code(204)
// Replace with `reply.send()`, and everything works.
return null
},
})
await app.listen({
port: 3000,
})
```
Run code above.
Run `wget -q -S -O- --post-data='{}' --header='Content-Type:application/json' 'http://127.0.0.1:3000/json'`
My output is:
```
HTTP/1.1 204 No Content
content-type: application/json; charset=utf-8
content-length: 4
Date: Tue, 29 Aug 2023 12:58:12 GMT
Connection: keep-alive
Keep-Alive: timeout=72
```
### Expected Behavior
Response header `content-length` should be `0` or omitted when `204` status code is set. | https://github.com/fastify/fastify/issues/5003 | https://github.com/fastify/fastify/pull/5056 | 16859bb0ca643b9e34be6fa4bff4a4ff9efa8289 | cefe85d16e378a04b3e38557c6e81e4eda61d363 | "2023-08-29T13:18:41Z" | javascript | "2023-10-04T07:57:23Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 4,993 | ["test/types/request.test-d.ts", "types/request.d.ts"] | Tighten `FastifyRequest.id` type | ### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the bug has not already been reported
### Fastify version
4.21
### Plugin version
_No response_
### Node.js version
16.x
### Operating system
macOS
### Operating system version (i.e. 20.04, 11.3, 10)
Ventura 13.5.1
### Description
Accessing the `id` field on the request object lead my Eslint to complain I was operating on an `any`. I hope and don't imagine this should be a different type.
https://github.com/fastify/fastify/blob/7270c007feda525cb4feb574ea310003ad0b7aa8/types/request.d.ts#L53
Can we tighten it to a `string`?
### Steps to Reproduce
https://github.com/fastify/fastify/blob/7270c007feda525cb4feb574ea310003ad0b7aa8/types/request.d.ts#L53
### Expected Behavior
Type should be a `string` | https://github.com/fastify/fastify/issues/4993 | https://github.com/fastify/fastify/pull/4992 | 8974714cddce705c190f344de383618f9d8cdde1 | 889456f2c6c4ff9fbd907c9ba6cf3527808b4ac7 | "2023-08-25T05:08:07Z" | javascript | "2023-08-26T20:20:25Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 4,925 | ["fastify.js", "lib/pluginOverride.js", "lib/pluginUtils.js", "test/internals/plugin.test.js", "test/plugin.test.js"] | `hasPlugin` does not check outer scopes | ### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the bug has not already been reported
### Fastify version
4.20.0
### Plugin version
_No response_
### Node.js version
18.16.1
### Operating system
Windows
### Operating system version (i.e. 20.04, 11.3, 10)
11
### Description
`hasPlugin` does not check outer scopes for registered plugins
### Steps to Reproduce
```
import fastify from 'fastify'
import fastifyPlugin from 'fastify-plugin'
const server = fastify()
const pluginCallback = (server, options, done) => {
done()
}
const pluginName = 'awesome-plugin'
const plugin = fastifyPlugin(pluginCallback, {name: pluginName})
await server.register(plugin)
await server.register(async (server) => {
const hasPlugin = server.hasPlugin(pluginName)
console.log(hasPlugin) // prints: false
const hasPluginWorkaround =
server[Symbol.for('registered-plugin')]
.includes(pluginName)
console.log(hasPluginWorkaround) // prints: true
})
```
### Expected Behavior
`hasPlugin` should be `true` | https://github.com/fastify/fastify/issues/4925 | https://github.com/fastify/fastify/pull/4929 | 395b9117bf0c49406a2ae1f7cdb761aa07f9d41c | d8165ef18baa0b174137209a248da51d08575b4a | "2023-07-21T14:05:57Z" | javascript | "2023-07-28T10:03:35Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 4,917 | ["README.md"] | OpenSSF CII Best Practices badge | Hi folks! I chatted with @mcollina and he suggested I file an issue.
For my @OpenJS-foundation "Security Engineering Champion" role, i'm working on getting the [OpenSSF best practices badge](https://bestpractices.coreinfrastructure.org/) on a bunch of OpenJS projects. I did [nvm](https://github.com/nvm-sh/nvm), and now i'm planning to work on fastify. I'm hoping that's OK with all of you?
I've created a [best practices project](https://bestpractices.coreinfrastructure.org/en/projects/7585) myself, and can later add any maintainers who create an account and give me their user ID (so yall can maintain it moving forward).
Assuming this is OK, I'll likely be asking questions as i go to clarify, but the intention is to spare you folks the majority of the work to document what you're already doing. | https://github.com/fastify/fastify/issues/4917 | https://github.com/fastify/fastify/pull/4926 | b31b1b48a148e8fae4d65a7b8eb2d271389d02db | 5473ce398abbf99862ef900c42c3f2067324f183 | "2023-07-18T23:47:21Z" | javascript | "2023-07-22T07:14:07Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 4,911 | ["lib/errors.js", "lib/reply.js", "test/async-await.test.js", "test/internals/errors.test.js", "test/internals/reply.test.js", "test/serial/logger.0.test.js"] | Detect invalid return values which cause major (and very hard to debug) application errors | ### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the feature has not already been requested
### 🚀 Feature Proposal
If a URL handler uses `async`/`await` and does not return the reply object, then this will silently break the application in a manner very hard to debug.
Please see https://github.com/fastify/fastify/issues/4908 and possibly https://github.com/fastify/fastify/issues/3994
EG this code:
```
app.get(
"*",
async (req, reply) => {
reply.send("hello");
}
);
```
The solution is [documented here](https://fastify.dev/docs/latest/Reference/Routes/#async-await) but the problem is easily overlooked.
The correct answer is to either (a) `return reply` (b) `return reply.send(...)`, or (c) `await reply`, however if you use the code above fastify/your app will call `reply.send` twice, causing the underlying HTTP implementation to throw an error.
It is **virtually impossible** to determine what caused the exception to be thrown by the underlying node HTTP library, even by debugging the fastify code.
From an end users point of view, the data has been sent (ie `reply.send()` has been called) and all promises have been awaited for - but gotcha! we have to know to await something not generally considered to be a promise, or return it.
Are there any circumstances when a URL handler can return a promise which resolves as `undefined`? AIUI the only time would be if the handler used `await reply` already.
It would be **massively** more helpful to detect a return of `undefined` and warn the user that is probably not correct, and then to `await reply` before continuing.
### Motivation
The silent killer nature of this problem (which exhibits itself as an exception thrown by the underlying node http library) means that there is no clue as to the problem.
### Example
_No response_ | https://github.com/fastify/fastify/issues/4911 | https://github.com/fastify/fastify/pull/4921 | 7b0f8ed28c425f724e22be1e4a388d4dcba81661 | 5fa052ebc155af01b77167bd697b06ac3844e6e4 | "2023-07-17T13:53:26Z" | javascript | "2023-07-24T12:34:03Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 4,896 | ["test/types/instance.test-d.ts", "types/instance.d.ts"] | setNotFoundHandler handler return type does not support `return` | ### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the bug has not already been reported
### Fastify version
4.19.2
### Plugin version
_No response_
### Node.js version
20.x
### Operating system
macOS
### Operating system version (i.e. 20.04, 11.3, 10)
13.4.1
### Description
I'm trying to customize my 404 experience, but the handler return type for `setNotFoundHandler` is complaining. Everything works as expected when I `@ts-ignore` the line so I think this is just a bug in the type system. I have a similar handler for my index `/` route and it does not have the typescript error.
The complete TypeScript error is:
```
Argument of type '(request: FastifyRequest<RouteGenericInterface, Server<typeof IncomingMessage, typeof ServerResponse>, IncomingMessage, ... 4 more ..., ResolveFastifyRequestType<...>>, reply: FastifyReply<...>) => FastifyReply<...> | ... 1 more ... | { ...; }' is not assignable to parameter of type '(request: FastifyRequest<RouteGenericInterface, Server<typeof IncomingMessage, typeof ServerResponse>, IncomingMessage, ... 4 more ..., ResolveFastifyRequestType<...>>, reply: FastifyReply<...>) => void | Promise<...>'.
Type 'FastifyReply<RawServerDefault, IncomingMessage, ServerResponse<IncomingMessage>, RouteGenericInterface, unknown, FastifySchema, FastifyTypeProviderDefault, unknown> | "Not found\n" | { ...; }' is not assignable to type 'void | Promise<unknown>'.
Type 'FastifyReply<RawServerDefault, IncomingMessage, ServerResponse<IncomingMessage>, RouteGenericInterface, unknown, FastifySchema, FastifyTypeProviderDefault, unknown>' is not assignable to type 'void | Promise<unknown>'.
Type 'FastifyReply<RawServerDefault, IncomingMessage, ServerResponse<IncomingMessage>, RouteGenericInterface, unknown, FastifySchema, FastifyTypeProviderDefault, unknown>' is missing the following properties from type 'Promise<unknown>': catch, finally, [Symbol.toStringTag]ts(2345)
```
Do any current type maintainers have an idea what the fix is?
### Steps to Reproduce
```ts
import { fileURLToPath } from 'node:url';
import { dirname, join } from 'node:path';
import fastify from 'fastify';
const app = fastify({
logger: true,
});
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
void app.register(import('@fastify/accepts'));
void app.register(import('@fastify/static'), {
root: join(__dirname, '../public'),
});
// TypeScript fails here at `handler`
app.setNotFoundHandler(function handler(request, reply) {
const accept = request.accepts();
switch (accept.type(['html', 'json'])) {
case 'html': {
void reply.type('text/html');
return reply.sendFile('404.html');
}
case 'json': {
void reply.type('application/json');
return {"message":`Route ${request.method}:${request.url} not found`,"error":"Not Found","statusCode":404}
}
default: {
void reply.code(404);
return 'Not found\n';
}
}
})
// But TypeScript does not fail here
app.get('/', function handler(request, reply) {
const accept = request.accepts();
switch (accept.type(['html', 'json'])) {
case 'html': {
void reply.type('text/html');
return reply.sendFile('index.html');
}
case 'json': {
void reply.type('application/json');
return { data: `Welcome to my app!` };
}
default:
return `Welcome to my app!\n`;
}
});
export { app };
```
### Expected Behavior
I expect TypeScript not to fail. | https://github.com/fastify/fastify/issues/4896 | https://github.com/fastify/fastify/pull/4897 | 66bad3e68df5fa32e5fa36274b04a1fd4a266e86 | 59c5b273dad30821d03c952bbe073a976f92a325 | "2023-07-10T19:32:06Z" | javascript | "2023-07-12T07:29:39Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 4,891 | [".github/dependabot.yml", ".github/workflows/pull-request-title.yml"] | Considering enforcing conventional commit specification | ### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the issue has not already been raised
### Issue
Whilst the release notes are great at showing what changed and who committed what, the individual items are a mixed bag, and make it difficult to skim read.
As an example from v4.19.0:
![image](https://github.com/fastify/fastify/assets/43814140/237fa2ce-aa73-4c41-b954-40e1c7072f4d)
From a glance, I can't tell what that `pluginName will be exposed in FastifyInstance` change is. Is it a bugfix? Is it a new feature? Was it just the documentation that was updated? The other two items in the list I can clearly see what type of change they were.
I think this could be remedied by enforcing the use of the [conventional commit specification](https://www.conventionalcommits.org/en/v1.0.0/) using the [Angular convention](https://github.com/angular/angular/blob/22b96b9/CONTRIBUTING.md#type) with commitlint in a husky hook and/or the [commitlint GH Action](https://github.com/wagoid/commitlint-github-action).
| https://github.com/fastify/fastify/issues/4891 | https://github.com/fastify/fastify/pull/4951 | c7392f8d4a4fd10f93e54fbdcbf7f6694b2803b1 | ace58fe4b64e217fe7f49bf564c5fa6a255c1196 | "2023-07-09T08:27:26Z" | javascript | "2023-08-04T08:31:00Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 4,883 | ["test/types/reply.test-d.ts", "types/reply.d.ts"] | reply.code().send() does not infer correct type | ### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the regression has not already been reported
### Last working version
4.18.0
### Stopped working in version
4.19.0
### Node.js version
18.16.0
### Operating system
macOS
### Operating system version (i.e. 20.04, 11.3, 10)
13.2.1
### 💥 Regression Report
Upgrading from 4.18.0 to 4.19.x `reply.code().send()` can no longer infer the correct type if the provided type is an `Array<T>.` Seems to do with this commit: 7d02f769ee81abba336fd7a7988b0797a6948dfe.
```
type ReplyTypeConstrainer<RouteGenericReply, Code extends ReplyKeysToCodes<keyof RouteGenericReply>, ReplyKey = CodeToReplyKey<Code>> =
Code extends keyof RouteGenericReply ? RouteGenericReply[Code] :
[ReplyKey] extends [never] ? unknown :
ReplyKey extends keyof RouteGenericReply ? RouteGenericReply[ReplyKey] :
unknown;
```
```
type TestReplyType = ReplyTypeConstrainer<string[], 200>; // TestReplyType is a string because it fulfils the first condition of ReplyTypeConstrainer
```
Is the intended behaviour to force users to implement the reply type as `{ [code: number]: any }`, or are users still allowed to provide any type as a reply?
### Steps to Reproduce
```
import fastify from '../fastify'
const server = fastify()
type TestResponse = string[];
server.get<{ Reply: TestResponse }>(
'/ping',
{ schema: {} },
async (request, reply) => {
reply.code(200).send(['']) // type error
}
)
server.listen({ port: 8080 }, (err, address) => {
if (err) {
console.error(err)
process.exit(1)
}
console.log(`Server listening at ${address}`)
})
```
### Expected Behavior
The correct type should be inferred, or strict even more the reply type to be a Record<HttpStatusCode, unknown>. | https://github.com/fastify/fastify/issues/4883 | https://github.com/fastify/fastify/pull/4885 | 5fa052ebc155af01b77167bd697b06ac3844e6e4 | 9d2da7586dc2ff02414f2e25245ab657244275ac | "2023-07-06T12:52:16Z" | javascript | "2023-07-26T08:29:28Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 4,870 | ["test/types/instance.test-d.ts", "types/instance.d.ts"] | Example of `decorateRequest` can't pass type checking | ### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the issue has not already been raised
### Issue
https://fastify.dev/docs/latest/Reference/Decorators/#decoratereplyname-value-dependencies
```typescript
import { fastify } from 'fastify';
declare module 'fastify' {
interface FastifyRequest {
foo: Readonly<{ bar: number }>;
}
}
const app = fastify({});
// @ts-expect-error
app.decorateRequest('foo', null); <- `null` doens't satisfy type `{bar: number}`
app.addHook('onRequest', async (req, reply) => {
req.foo = { bar: 42 };
});
```
I don't think change type of `.foo` to `... | null` is a good idea, so the only possible solution I can come up with is to use `@ts-ignore` or `@ts-expect-error` on line `decorateRequest`.
caused by https://github.com/fastify/fastify/pull/4858 | https://github.com/fastify/fastify/issues/4870 | https://github.com/fastify/fastify/pull/4874 | 2d9e695839bc201fa639626731c61b12d2a9074b | 956bc05cfcd816e5b40ca1aea8cb45c9729f0711 | "2023-07-02T18:55:44Z" | javascript | "2023-07-03T12:36:12Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 4,866 | ["lib/route.js", "package.json", "test/constrained-routes.test.js"] | HEAD requests are resolving to wildcard routes instead of named routes | ### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the bug has not already been reported
### Fastify version
4.0.0
### Plugin version
_No response_
### Node.js version
20.3.1
### Operating system
macOS
### Operating system version (i.e. 20.04, 11.3, 10)
macOS Ventura 13.4.1
### Description
A HEAD request to a named route is resolving to the wildcard route instead while GET requests resolve correctly.
### Steps to Reproduce
I've put a simple repo here https://github.com/andokai/head-issue
The issue is demonstrated in the failing test in `example.test.js`.
### Expected Behavior
The content-length header for the HEAD request should match the equivalent header for the GET request and it shouldn't match the header for the GET request of the wildcard route. | https://github.com/fastify/fastify/issues/4866 | https://github.com/fastify/fastify/pull/5078 | b59b0a5dcc38f2b81b5ee38e92070efb7bea1c69 | 797f27d7b6fde7c616bc63fe51201b5a6843f8ab | "2023-07-01T10:14:45Z" | javascript | "2023-10-11T10:44:20Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 4,859 | ["test/types/hooks.test-d.ts", "types/hooks.d.ts", "types/route.d.ts"] | Support `RouteShorthandOptions` to receive async hooks | ### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the issue has not already been raised
### Issue
Currently, `RouteShorthandOptions` type doesn't allow passing async hooks:
```ts
export interface RouteShorthandOptions<
// ...
> {
// ...
onRequest?: onRequestHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
| onRequestHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>[];
```
It should be something like that:
```ts
export interface RouteShorthandOptions<
// ...
> {
// ...
onRequest?: onRequestHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
| onRequestHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>[]
// Add these two:
| onRequestAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
| onRequestAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>[];
``` | https://github.com/fastify/fastify/issues/4859 | https://github.com/fastify/fastify/pull/5147 | e9764f3c004bc5c67441456d0e4612d35988db6c | 49b62f56a35f1a9a958de6aec07cee851ac2aa43 | "2023-06-27T07:53:34Z" | javascript | "2023-12-10T11:27:58Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 4,843 | ["fastify.js"] | Memory Leak: fastify instance kept in memory after calling .close() | ### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the bug has not already been reported
### Fastify version
4.13.0
### Plugin version
_No response_
### Node.js version
v18.16.1
### Operating system
macOS
### Operating system version (i.e. 20.04, 11.3, 10)
13.0.1
### Description
We are experiencing OOM errors in our tests, both locally (macOS) and in CI (linux).
After some analysis we found that the fastify instances are kept in memory even after `.close()` was called.
We were able to reproduce this in a minimal reproduction, where only the repeated invocation of `Fastify().close()` leads to the allocation of more and more memory.
![Screenshot 2023-06-22 at 09 33 19](https://github.com/fastify/fastify/assets/111499660/8d43755b-d406-46fa-827b-d640d865d0cd)
What looks interesting is the `connectionsCheckingInterval`. This is new in Node.js v18.0.0: https://nodejs.org/api/http.html#httpcreateserveroptions-requestlistener. When running the script with Node.js v16.13.0, memory still increases, but not as much and there are no Router/Server instances in memory after the script has finished.
### Steps to Reproduce
```
// memory-test.js
const Fastify = require('fastify')
const initialRss = process.memoryUsage().rss
async function main() {
for (let i = 0; i < 2000; i += 1) {
if (i % 100 === 0) {
global.gc()
console.log('server', i, process.memoryUsage().rss - initialRss)
}
const server = Fastify()
// eslint-disable-next-line no-await-in-loop
await server.close()
}
await new Promise(resolve => setTimeout(resolve, 1000))
global.gc()
debugger
}
main()
```
Run with `node --expose-gc ./memory-test.js` to see logs or `node --inspect-brk --expose-gc ./memory-test.js` to analyse memory allocation.
### Expected Behavior
Fastify instances being freed after calling .close(). | https://github.com/fastify/fastify/issues/4843 | https://github.com/fastify/fastify/pull/4860 | 6c3e37cab2e35a533c65beb3df58cf857c7211c4 | 3a52ca662a8ed2c010b82dd27964a3dd34f50c01 | "2023-06-22T07:44:58Z" | javascript | "2023-06-30T09:30:45Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 4,842 | ["package.json"] | Tests are failing in Windows due to command line env syntax | ### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the issue has not already been raised
### Issue
Running `npm run test` fails because the env syntax is different on windows and unix systems. Following is the error
```log
C:\Users\aaron\Documents\projects\fastify>npm run test
> [email protected] test
> npm run lint && NODE_OPTIONS=no-network-family-autoselection npm run unit && npm run test:typescript
> [email protected] lint
> npm run lint:standard && npm run lint:typescript && npm run lint:markdown
> [email protected] lint:standard
> standard | snazzy
> [email protected] lint:typescript
> eslint -c types/.eslintrc.json types/**/*.d.ts test/types/**/*.test-d.ts
> [email protected] lint:markdown
> markdownlint-cli2
markdownlint-cli2 v0.5.1 (markdownlint v0.26.2)
'NODE_OPTIONS' is not recognized as an internal or external command,
operable program or batch file.
C:\Users\aaron\Documents\projects\fastify>
```
### Solution:
Use a platform agnostic solution to set env | https://github.com/fastify/fastify/issues/4842 | https://github.com/fastify/fastify/pull/4845 | 5992c0bea713db8d46274b4756a3db12b5651fd1 | 49b416c8f58190e393f782478d70a00f4e054e82 | "2023-06-21T17:42:36Z" | javascript | "2023-06-22T18:08:14Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 4,831 | ["docs/Reference/Routes.md"] | Constraints option missing | ### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the issue has not already been raised
### Issue
At `Routes.md` - > **`Route options`** `constraints` option iwith short description is missing. A section related to the topic just appears in the end of the page. *Tia* | https://github.com/fastify/fastify/issues/4831 | https://github.com/fastify/fastify/pull/4838 | 639e15a05bbedad1a2030aa30430b6e619dcc61b | 5992c0bea713db8d46274b4756a3db12b5651fd1 | "2023-06-18T17:26:22Z" | javascript | "2023-06-20T19:56:39Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 4,829 | ["docs/Reference/Errors.md", "lib/errors.js", "lib/server.js", "test/internals/errors.test.js", "test/server.test.js"] | Synchronous start Fastify server to listen receives aborted signal from `AbortController` before `listenCallback.call`. | ### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the bug has not already been reported
### Fastify version
4.18.0
### Plugin version
_No response_
### Node.js version
v16.16.0
### Operating system
macOS
### Operating system version (i.e. 20.04, 11.3, 10)
10.11.6
### Description
The example from https://www.fastify.io/ of Fastify server start (TypeScript Support ) has an issue with ignoring abort signal.
Probably issue related to call [this.ready(listenCallback.call(this, server, listenOptions))](https://github.com/fastify/fastify/blob/61b86760019c85afbef6cc0f175c75870381ed04/lib/server.js#L100) of `createServer(...)` sub-function `listen(listenOptions, ...args)` at`lib/server.js` because [server.listen(listenOptions, wrap)](https://github.com/fastify/fastify/blob/61b86760019c85afbef6cc0f175c75870381ed04/lib/server.js#L195) has been called with already true aborted signal.
```js
listenOptions before call this.ready(listenCallback.call(this, server, listenOptions))
{
port: 0,
signal: AbortSignal { aborted: false },
cb: [Function (anonymous)],
host: 'localhost'
}
listenOptions before call server.listen(listenOptions, wrap)
{
port: 0,
signal: AbortSignal { aborted: true },
cb: [Function (anonymous)],
host: 'localhost'
}
listenOptions before call server.listen(listenOptions, wrap)
{
port: 54991,
signal: AbortSignal { aborted: true },
cb: [Function: cb],
host: '::1'
}
```
### Steps to Reproduce
```typescript
const controller = new AbortController();
server.listen({port: 0, signal: controller.signal}, () => { console.log(server.server.address())});
controller.abort();
```
### Expected Behavior
Expected behaviour should be the same to call `listen(...)` of RawServer or at least documentation should be updated.
```typescript
const controller = new AbortController();
server.server.listen({port: 0, signal: controller.signal}, () => { console.log(server.server.address())});
controller.abort();
``` | https://github.com/fastify/fastify/issues/4829 | https://github.com/fastify/fastify/pull/4886 | 53164c16f640bfe936b61757bb15dbc29fee99c2 | 1c50da371c1ede2bd344cf5b52bbd9f3ebdd12a0 | "2023-06-17T14:31:38Z" | javascript | "2023-07-13T07:53:38Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 4,808 | ["fastify.js", "test/router-options.test.js"] | Inconsistent logger call in frameworksError wrapper | ### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the bug has not already been reported
### Fastify version
4.17.0
### Plugin version
_No response_
### Node.js version
16.x
### Operating system
macOS
### Operating system version (i.e. 20.04, 11.3, 10)
11.7
### Description
The wrapper for `frameworkErrors` custom handler in `fastify.js`, `onBadUrl()` supplies _raw_ request to the "incoming request" logger, unlike in normal logging case in `route.js`.
This breaks input expectation for custom logger's request serializer - normally `req` argument is Fastify request, but in this case it is raw request. This can lead to an exception.
BTW, it also doesn't honor `disableRequestLogging` option in this case.
Same is true for `onAsyncConstraintError` framework error case.
See also #4807
### Steps to Reproduce
```js
test('Should supply Fastify request to the logger in frameworkErrors wrapper - FST_ERR_BAD_URL', t => {
t.plan(5)
const logStream = split(JSON.parse)
const fastify = Fastify({
frameworkErrors: function (err, req, res) {
res.send(`${err.message} - ${err.code}`)
},
logger: {
stream: logStream,
serializers: {
req (request) {
return { httpVersion: request.raw.httpVersion }
// ^^^
// test/router-options.test.js 2> TypeError: Cannot read properties of undefined (reading 'httpVersion')
}
}
},
genReqId: () => 'REQ-1234'
})
fastify.get('/test/:id', (req, res) => {
res.send('{ hello: \'world\' }')
})
logStream.on('data', (json) => {
console.log(json)
t.same(json.msg, 'incoming request')
t.same(json.reqId, 'REQ-1234')
t.same(json.httpVersion, '1.1')
})
fastify.inject(
{
method: 'GET',
url: '/test/%world'
},
(err, res) => {
t.error(err)
t.equal(res.body, '\'/test/%world\' is not a valid url component - FST_ERR_BAD_URL')
}
)
})
```
### Expected Behavior
Should supply Fastify request object | https://github.com/fastify/fastify/issues/4808 | https://github.com/fastify/fastify/pull/4825 | 3230a10fa4d682ad8d676705941654e1e3203b77 | 433439f94c2c82ba6c15791fe74c7e8bb0daf4a4 | "2023-06-09T12:18:52Z" | javascript | "2023-06-25T10:48:15Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 4,807 | ["lib/request.js", "test/inject.test.js", "test/internals/reply.test.js", "test/internals/request.test.js"] | Accessing req.routeConfig in frameworkErrors handler throws TypeError | ### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the bug has not already been reported
### Fastify version
4.17.0
### Plugin version
_No response_
### Node.js version
16.x
### Operating system
macOS
### Operating system version (i.e. 20.04, 11.3, 10)
11.7
### Description
An attempt to get a value of `request.routeConfig` in `frameworkErrors` handler throws an exception:
```
test/router-options.test.js 2> return this[kRouteContext][kPublicRouteContext].config
test/router-options.test.js 2> ^
test/router-options.test.js 2> TypeError: Cannot read properties of undefined (reading 'config')
```
### Steps to Reproduce
```js
test('Should not throw on access to routeConfig frameworkErrors handler - FST_ERR_BAD_URL', t => {
t.plan(6)
const fastify = Fastify({
frameworkErrors: function (err, req, res) {
t.ok(typeof req.id === 'string')
t.ok(req.raw instanceof Readable)
t.same(req.routerPath, undefined)
t.same(req.routeConfig, undefined)
// ^^^
// test/router-options.test.js 2> return this[kRouteContext][kPublicRouteContext].config
// test/router-options.test.js 2> ^
// test/router-options.test.js 2> TypeError: Cannot read properties of undefined (reading 'config')
res.send(`${err.message} - ${err.code}`)
}
})
fastify.get('/test/:id', (req, res) => {
res.send('{ hello: \'world\' }')
})
fastify.inject(
{
method: 'GET',
url: '/test/%world'
},
(err, res) => {
t.error(err)
t.equal(res.body, '\'/test/%world\' is not a valid url component - FST_ERR_BAD_URL')
}
)
})
```
### Expected Behavior
Should return `undefined` as, for example, `req.routerPath` does | https://github.com/fastify/fastify/issues/4807 | https://github.com/fastify/fastify/pull/4826 | 61b86760019c85afbef6cc0f175c75870381ed04 | c2b89732d583a0e0d8e0a666b2eb9b62610edf34 | "2023-06-09T12:06:44Z" | javascript | "2023-06-20T08:50:36Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 4,778 | ["test/types/reply.test-d.ts", "types/reply.d.ts"] | Reply `removeHeader()` return type incorrectly defined as void | ### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the bug has not already been reported
### Fastify version
4.17.0
### Plugin version
_No response_
### Node.js version
18.16.0
### Operating system
Windows
### Operating system version (i.e. 20.04, 11.3, 10)
11
### Description
The reply `removeHeader()` function can be chained, and does work when chained.
However, TypeScript will flag this as an issue with `Property 'removeHeader' does not exist on type 'void'.`, and refers to this line: https://github.com/fastify/fastify/blob/8540fb48762961ec3bd2ff2d2dfd9cd1e9cc225a/types/reply.d.ts#L46
I assume it just needs to be changed to use the same type as the other reply functions?
### Steps to Reproduce
Add the following hook to a Fastify instance:
```js
.addHook("onRequest", async (_req, res) => {
res.removeHeader("cache-control")
.removeHeader("expires")
.removeHeader("pragma")
.removeHeader("surrogate-control");
})
```
### Expected Behavior
For TypeScript to not throw an error. | https://github.com/fastify/fastify/issues/4778 | https://github.com/fastify/fastify/pull/4781 | 36e095db673876db96cad6c11d26fe661dadefcb | 13c358dc89da0662b08d77f6fd10a4cee9d3efdc | "2023-05-31T20:01:02Z" | javascript | "2023-06-03T08:47:32Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 4,774 | ["docs/Reference/Server.md", "lib/server.js", "test/close-pipelining.test.js", "test/close.test.js"] | `fastify.server.close()` did not behave as expected. | ### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the bug has not already been reported
### Fastify version
4.17.0
### Plugin version
_No response_
### Node.js version
v16.19.1
### Operating system
macOS
### Operating system version (i.e. 20.04, 11.3, 10)
12.6
### Description
According to the Node.js documentation:
```typescript
/**
* Stops the server from accepting new connections and keeps existing
* connections. This function is asynchronous, the server is finally closed
* when all connections are ended and the server emits a `'close'` event.
* The optional `callback` will be called once the `'close'` event occurs. Unlike
* that event, it will be called with an `Error` as its only argument if the server
* was not open when it was closed.
* @since v0.1.90
* @param callback Called when the server is closed.
*/
close(callback?: (err?: Error) => void): this;
```
The callback is supposed to be called when the server is closed. I've already tested it in the NodeJS HTTP server. However, in my case, when I call `fastify.server.close(callback)`, the callback is invoked immediately, and the server is still processing incoming requests instead of being closed.
> I'm reporting this issue because it breaks some of the shutdown features of `NestJS` (using `Fastify` adapter).
### Steps to Reproduce
```typescript
import Fastify from 'fastify';
const fastify = Fastify();
fastify.get('/', async (request, reply) => {
await new Promise((resolve) => {
setTimeout(() => resolve(1), 10000);
});
reply.send({ hello: 'world' });
});
setTimeout(() => {
fastify.server.close((error) => {
console.log('Server is closed', error);
});
}, 5000);
// Run the server!
fastify.listen({ port: 3000 }, (err, address) => {
if (err) throw err;
// Server is now listening on ${address}
});
```
Start the server and call the API at `localhost:3000`.
### Expected Behavior
The callback is only invoked when the server is actually closed as the original NodeJS HTTP server behaves.
> I'm reporting this issue because it breaks some of the shutdown features of `NestJS` (using `Fastify` adapter). | https://github.com/fastify/fastify/issues/4774 | https://github.com/fastify/fastify/pull/4776 | 49b416c8f58190e393f782478d70a00f4e054e82 | c4b8d85119068056df7d90782cd33841c943e062 | "2023-05-27T15:38:30Z" | javascript | "2023-06-23T13:52:58Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 4,769 | ["package.json"] | Some typescript tests are failing | ### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the bug has not already been reported
### Fastify version
4.17.0
### Plugin version
_No response_
### Node.js version
16.15.1
### Operating system
macOS
### Operating system version (i.e. 20.04, 11.3, 10)
12.6.5
### Description
When running the tests, specifically the `test:typescript` script, i'm seeing 31 errors:
```
> tsc test/types/import.ts && tsd
test/types/type-provider.test-d.ts:114:4
✖ 114:4 Parameter type number | undefined is not identical to argument type any.
✖ 114:35 Type instantiation is excessively deep and possibly infinite.
✖ 114:35 req.body is of type unknown.
✖ 115:4 Parameter type string | undefined is not identical to argument type any.
✖ 115:35 req.body is of type unknown.
✖ 116:4 Parameter type boolean | undefined is not identical to argument type any.
✖ 116:36 req.body is of type unknown.
✖ 141:4 Parameter type number | undefined is not identical to argument type any.
✖ 141:35 Type instantiation is excessively deep and possibly infinite.
✖ 141:35 req.body is of type unknown.
✖ 142:4 Parameter type string | undefined is not identical to argument type any.
✖ 142:35 req.body is of type unknown.
✖ 143:4 Parameter type boolean | undefined is not identical to argument type any.
✖ 143:36 req.body is of type unknown.
✖ 515:17 Type instantiation is excessively deep and possibly infinite.
✖ 526:2 Type instantiation is excessively deep and possibly infinite.
✖ 537:0 Type instantiation is excessively deep and possibly infinite.
✖ 537:17 Type instantiation is excessively deep and possibly infinite.
✖ 567:0 Type instantiation is excessively deep and possibly infinite.
✖ 567:0 Found an error that tsd does not currently support (ts2589), consider creating an issue on GitHub.
✖ 567:12 Type instantiation is excessively deep and possibly infinite.
✖ 587:0 Found an error that tsd does not currently support (ts2589), consider creating an issue on GitHub.
✖ 587:12 Type instantiation is excessively deep and possibly infinite.
✖ 615:17 Type instantiation is excessively deep and possibly infinite.
✖ 640:17 Type instantiation is excessively deep and possibly infinite.
✖ 673:0 Found an error that tsd does not currently support (ts2589), consider creating an issue on GitHub.
✖ 673:12 Type instantiation is excessively deep and possibly infinite.
✖ 690:0 Found an error that tsd does not currently support (ts2589), consider creating an issue on GitHub.
✖ 690:12 Type instantiation is excessively deep and possibly infinite.
✖ 704:0 Found an error that tsd does not currently support (ts2589), consider creating an issue on GitHub.
✖ 704:12 Type instantiation is excessively deep and possibly infinite.
31 errors
```
We've added fastify to our test suite that tests this module(and others) on different Fedora and RHEL platforms and started to see this error last night. related issue: https://github.com/sclorg/s2i-nodejs-container/issues/391
I've also run this locally on my macos laptop with Node 16(node 18 also) and getting the same thing.
I thought maybe it was happening just with the last HEAD, but i've checked out v4.17.0, which had been working previously and i'm seeing these failures there too
### Steps to Reproduce
* clone the repo
* npm install
* npm run test
### Expected Behavior
All the tests to pass | https://github.com/fastify/fastify/issues/4769 | https://github.com/fastify/fastify/pull/4770 | 410957f7e6018d4d3b07989c985df8b5af68ca3a | 4f367eabcdd70be5e969883c44290a83e8d5f18e | "2023-05-25T14:07:39Z" | javascript | "2023-05-25T18:37:57Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 4,753 | ["docs/Reference/Server.md", "fastify.d.ts", "fastify.js", "test/types/fastify.test-d.ts", "test/url-rewriting.test.js"] | Remove URL rewrite logging? | ### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the issue has not already been raised
### Issue
If the rewriteUrl function is used, then a debug log is generated:
https://github.com/fastify/fastify/blob/c4cb3a87cdbd33524556314341aa2b9bea61422f/fastify.js#L798-L800
This issue is more of a personal preference, but this behaviour creates a lot of extra log entries (1 per every request), which in my mind are not interesting.
My proposal is that the logging be removed. If the developer is interested in knowing when the URL is changed, then they can write their own log in the `rewriteUrl` function that they provide. Perhaps then we need to bind the `rewriteUrl` function to the fastify instance, or provide it as a parameter to they can access the logger easily.
Small bonus is that in this way we can also eliminate the URL equality check. | https://github.com/fastify/fastify/issues/4753 | https://github.com/fastify/fastify/pull/4754 | ca75d4c866c3140f49f768c4bb0cc3b3ece56cac | 410957f7e6018d4d3b07989c985df8b5af68ca3a | "2023-05-15T19:11:32Z" | javascript | "2023-05-23T11:48:35Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 4,732 | [".github/workflows/website.yml"] | broken Circle CI integration | ### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the issue has not already been raised
### Issue
The Circle CI token need to be updated.
The API endpoint also need to be updated.
![image](https://user-images.githubusercontent.com/23028015/236393364-9ba828a0-e31c-48df-b813-fdc17bbb38c7.png)
The website build trigger from `fastify/fastify` is broken since March.
That means whenever new document updated in here will not reflect in the website unless we manually run the build step on `fastify/website` or PR is merged in `fastify/website`.
Shell script for `v2` endpoint required to be tested by anyone who has Circle CI access.
[Circle CI Document](https://circleci.com/docs/api/v2/index.html#operation/triggerPipeline)
```sh
curl -X POST \
-H 'Content-Type: application/json' \
-H 'Circle-Token: ${{ secrets.circleci_token }}' \
-d '{"branch":"master"}' \
"https://circleci.com/api/v2/project/gh/fastify/website/pipeline"
```
cc @mcollina @luisorbaiceta @lmammino | https://github.com/fastify/fastify/issues/4732 | https://github.com/fastify/fastify/pull/4736 | 97b5ba7f2ed8ff8f69806bfaee1f689efef8fb8a | a6b17213a4f7a53ff451c64f2433c9798d0e3378 | "2023-05-05T06:53:38Z" | javascript | "2023-05-06T13:52:21Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 4,724 | ["package.json"] | Package Manager CI Failing with PNPM 8 | ### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the issue has not already been raised
### Issue
Bumped pnpm to use v8 in package manager CI workflow, however it is now failing when ran. ☹️
Cant see any breaking changes that would affect this in the v8 release notes: https://github.com/pnpm/pnpm/releases/tag/v8.0.0 | https://github.com/fastify/fastify/issues/4724 | https://github.com/fastify/fastify/pull/4726 | be137713136ba5f7bd4c22805ebc501b3412565f | 8e7c7a4ab36da58e7079a4f9f6aaafa6b91dffa2 | "2023-05-02T14:17:58Z" | javascript | "2023-05-03T06:30:47Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 4,706 | ["docs/Reference/Logging.md", "test/types/logger.test-d.ts", "types/logger.d.ts"] | Crash when using `reply` in a response log serializers and a request using an unsupported HTTP version is sent | ### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the bug has not already been reported
### Fastify version
4.16.3
### Plugin version
_No response_
### Node.js version
18.16.0
### Operating system
macOS
### Operating system version (i.e. 20.04, 11.3, 10)
13.2.1
### Description
When a custom response log serializer uses fields from `reply` other than `statusCode`, Fastify crashes if a request using an unsupported HTTP version is received.
### Steps to Reproduce
fastify server:
```
const Fastify = require('fastify');
const fastify = Fastify({
logger: {
serializers: {
res(reply) {
return {
statusCode: reply.statusCode,
headers: reply.getHeaders()
}
}
}
}
});
fastify.get('/', async () => 'hello, world');
fastify.listen({ port: 3000 });
```
send a request using telnet:
```
> telnet localhost 3000
Trying ::1...
Connected to localhost.
Escape character is '^]'.
GET / HTTP/0.9
Connection closed by foreign host.
```
Fastify crashes with stack trace:
```
{"level":30,"time":1682523174228,"pid":6053,"hostname":"bcd0744fbac0","msg":"Server listening at http://[::1]:3000"}
{"level":30,"time":1682523174229,"pid":6053,"hostname":"bcd0744fbac0","msg":"Server listening at http://127.0.0.1:3000"}
/Users/me/scratch/fastify-crash-repro/app.js:9
headers: reply.getHeaders()
^
TypeError: reply.getHeaders is not a function
at Object.res (/Users/me/scratch/fastify-crash-repro/app.js:9:26)
at Pino.asJson (/Users/me/scratch/fastify-crash-repro/node_modules/pino/lib/tools.js:132:33)
at Pino.write (/Users/me/scratch/fastify-crash-repro/node_modules/pino/lib/proto.js:205:28)
at Pino.LOG [as info] (/Users/me/scratch/fastify-crash-repro/node_modules/pino/lib/tools.js:62:21)
at Object.routeHandler [as handler] (/Users/me/scratch/fastify-crash-repro/node_modules/fastify/lib/route.js:415:19)
at Router.callHandler (/Users/me/scratch/fastify-crash-repro/node_modules/find-my-way/index.js:398:14)
at Router.lookup (/Users/me/scratch/fastify-crash-repro/node_modules/find-my-way/index.js:376:17)
at Server.preRouting (/Users/me/scratch/fastify-crash-repro/node_modules/fastify/fastify.js:799:14)
at Server.emit (node:events:513:28)
at parserOnIncoming (node:_http_server:1091:12)
Node.js v18.16.0
```
This is caused because a less-than-complete `reply` object is passed for `res` in the log message here: https://github.com/fastify/fastify/blob/main/lib/route.js#L415
There's another similar occurrence here: https://github.com/fastify/fastify/blob/main/lib/route.js#L444
### Expected Behavior
I think there are a two potential issues here:
1. the `res` log serializer is called with a less-than-complete `reply` object. This should either be addressed if possible, or clarified in the documentation and types otherwise. Currently it says:
> The object received by req is the Fastify [Request](https://www.fastify.io/docs/latest/Reference/Request) object, while the object received by res is the Fastify [Reply](https://www.fastify.io/docs/latest/Reference/Reply) object
2. An error thrown from a log serializer should not crash the Fastify server. | https://github.com/fastify/fastify/issues/4706 | https://github.com/fastify/fastify/pull/4716 | 72e1a7c28147d1a540fd7510f1beef02681dc4ce | be137713136ba5f7bd4c22805ebc501b3412565f | "2023-04-26T15:45:16Z" | javascript | "2023-05-02T14:11:45Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 4,705 | ["test/types/hooks.test-d.ts", "types/hooks.d.ts", "types/route.d.ts"] | typings for the route config based hooks no longer working since 4.16.0 | ### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the bug has not already been reported
### Fastify version
4.16.0
### Plugin version
_No response_
### Node.js version
18.x
### Operating system
macOS
### Operating system version (i.e. 20.04, 11.3, 10)
12.3
### Description
The hooks specified in the options of a [route](https://www.fastify.io/docs/latest/Reference/Routes/) no longer have the correct typings applied/resolved. They come back as `any`. The following code snippet works in `4.15.0`, but breaks in `4.16.0`
### Steps to Reproduce
```typescript
import Fastify from "fastify";
const fastify = Fastify();
fastify.get(
"/route",
{
onError: (request, reply, error) => {
request // is any
reply // is any
error // is any
},
},
async () => ({ success: "yes" })
);
```
The same appears to be true for all the other hooks specified in this manner as well.
Interestingly, hooks added with `addHook` appear to have the correct typings resolved
### Expected Behavior
_No response_ | https://github.com/fastify/fastify/issues/4705 | https://github.com/fastify/fastify/pull/5147 | e9764f3c004bc5c67441456d0e4612d35988db6c | 49b62f56a35f1a9a958de6aec07cee851ac2aa43 | "2023-04-26T13:51:56Z" | javascript | "2023-12-10T11:27:58Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 4,661 | [".github/workflows/labeler.yml"] | bug: labeller bot removes the label | The labeller bod should not remove the labels when already set:
https://github.com/fastify/fastify/blob/6eb145aeb905b6c9e1a84cdc67ae8b9f038fd5fd/.github/labeler.yml#L6
<img width="681" alt="image" src="https://user-images.githubusercontent.com/11404065/229888854-b2d268ef-3a80-4de0-b792-7d8bbcf6ffba.png">
| https://github.com/fastify/fastify/issues/4661 | https://github.com/fastify/fastify/pull/4662 | ab32174cd8dfb3e2099a98ccdd599dd030f8738e | 30eba8b97be115843f00f63ea377d80ac8940c73 | "2023-04-04T18:45:06Z" | javascript | "2023-04-05T16:09:44Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 4,643 | [".github/workflows/integration.yml", ".github/workflows/package-manager-ci.yml"] | Install specific versions of pnpm for CI | https://github.com/fastify/fastify/blob/f1991cf60a8034161ea226344c902903d7a6d138/.github/workflows/package-manager-ci.yml#L31-L34
https://github.com/fastify/fastify/actions/runs/4546742715/jobs/8015757124#step:4:16
![image](https://user-images.githubusercontent.com/321201/228344496-37613ea5-b45f-44dc-b559-50ce21d679dc.png)
| https://github.com/fastify/fastify/issues/4643 | https://github.com/fastify/fastify/pull/4645 | bf1214879d9ad7baecba0b9af7d1e9ddbf41044e | bfedfd12e8deecbc2cb6be58e1e6a7e226b3020b | "2023-03-28T19:19:15Z" | javascript | "2023-03-30T09:10:33Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 4,637 | ["docs/Guides/Migration-Guide-V4.md", "docs/Reference/Routes.md"] | Optional URL parameter not working after upgrading to Fastify v4 | ### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the issue has not already been raised
### Issue
Hi there,
After upgrading Fastify from v3 (`3.29.1`) to v4 (`4.15.0`), I encountered a breaking change that was not mentioned in the [upgrade guide](https://github.com/fastify/fastify/blob/main/docs/Guides/Migration-Guide-V4.md). The issue is about optional URL building.
Before the upgrade, I had a route similar to the following, where "a" was required but "b" was optional:
```ts
fastify.get('/:a/:b', (request, reply) => {
const { a, b } = request.params;
});
```
However, after upgrading to v4, some of my integration tests were broken, and I realized that requests without a value for "b" were returning a "404 fallback reached" error. Adding a question mark at the end of the optional variable fixed the issue:
```ts
fastify.get('/:a/:b?', (request, reply) => {
const { a, b } = request.params;
});
```
I didn't find anything about this in the [URL building docs](https://github.com/fastify/fastify/blob/main/docs/Reference/Routes.md#url-building) or the upgrade guide. However, I can contribute to the project, but I need guidance on where to place it. | https://github.com/fastify/fastify/issues/4637 | https://github.com/fastify/fastify/pull/4680 | 831500088f5ba48f02129db2fc822946d40597ff | bc3f95734581c1fa22e1c4a4da9b898cf9e3ec7f | "2023-03-22T18:13:32Z" | javascript | "2023-04-19T07:59:26Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 4,634 | ["lib/validation.js", "lib/warnings.js", "test/schema-feature.test.js"] | Error: Schema for validaton is undefined | ### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the bug has not already been reported
### Fastify version
4.15.0
### Plugin version
_No response_
### Node.js version
any
### Operating system
Windows
### Operating system version (i.e. 20.04, 11.3, 10)
10
### Description
4.15 release have a backward compatibility issue ([PR](https://github.com/fastify/fastify/pull/4620)): it throws an error if schema for validation is undefined.
For example, we get a schemas and pass them to fastify.
```ts
const { headers, body } = getSchemas();
fastify.post('/', {
schema: {
headers,
body
}
}
```
### Steps to Reproduce
```ts
const fastify = require("fastify")({ logger: true });
fastify.get(
"/",
{
schema: {
headers: undefined,
},
},
() => {
return "hello";
}
);
const start = async () => {
try {
await fastify.listen({ port: 3000 });
} catch (err) {
fastify.log.error(err);
process.exit(1);
}
};
start();
```
Server throws an error `Failed building the validation schema for GET: /, due to error headers schema is undefined"` when started
### Expected Behavior
I think that `undefined` is acceptable value, which means that validation will be skipped. | https://github.com/fastify/fastify/issues/4634 | https://github.com/fastify/fastify/pull/4647 | 30eba8b97be115843f00f63ea377d80ac8940c73 | d0a1e8c1c9be33aa6cae9631163dd18e2bd3f784 | "2023-03-20T14:45:00Z" | javascript | "2023-04-07T06:56:51Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 4,629 | ["package.json"] | error TS2614: Module '"@fastify/fast-json-stringify-compiler"' has no exported member 'SerializerFactory' | ### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the bug has not already been reported
### Fastify version
4.14
### Plugin version
_No response_
### Node.js version
v16.19.1
### Operating system
Linux
### Operating system version (i.e. 20.04, 11.3, 10)
22.04.2
### Description
Hi,
running Typescripts tsc (v4.9.5) from GitHub CI results in:
```
Error: node_modules/fastify/fastify.d.ts(8,33): error TS2614: Module '"@fastify/fast-json-stringify-compiler"' has no exported member 'SerializerFactory'. Did you mean to use 'import SerializerFactory from "@fastify/fast-json-stringify-compiler"' instead?
Error: node_modules/fastify/types/schema.d.ts(2,10): error TS2[6](https://github.com/seriousme/fastify-openapi-glue/actions/runs/4350791294/jobs/7748670225#step:11:7)14: Module '"@fastify/fast-json-stringify-compiler"' has no exported member 'SerializerFactory'. Did you mean to use 'import SerializerFactory from "@fastify/fast-json-stringify-compiler"' instead?
Error: Process completed with exit code 2.
```
I checked @fastify/fast-json-stringify-compiler and it looks to me like SerializerFactory tries to refer to:
`type FastJsonStringifyFactory = () => SerializerSelector.SerializerFactory`
https://github.com/fastify/fast-json-stringify-compiler/blob/a068619bafa4e2e8c449e6056a20f28a7711b4cd/types/index.d.ts#L3
Kind regards,
Hans
### Steps to Reproduce
See https://github.com/seriousme/fastify-openapi-glue/pull/461
4.13.0 has no issues, 4.14.0 and 14.14.1 break my CI
### Expected Behavior
No error | https://github.com/fastify/fastify/issues/4629 | https://github.com/fastify/fastify/pull/4630 | 4723c1b228f4a3d9e0ba38a137084b7fa2b622db | ca9785a3fadd9050ec163c6a0841a06f387a71c6 | "2023-03-15T19:54:02Z" | javascript | "2023-03-19T08:42:47Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 4,626 | ["lib/route.js", "test/hooks.test.js"] | Error handler for aborted request not called reliably | ### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the bug has not already been reported
### Fastify version
4.14.1
### Plugin version
_No response_
### Node.js version
18.15.0
### Operating system
Windows
### Operating system version (i.e. 20.04, 11.3, 10)
11
### Description
In #4611, logic was added to call the error handler when an aborted request is responded to. This broke one of our tests, since in v4.14.0, aborted requests only caused `onRequestAbort` to be called, but not also the error handler, which is behavior that we depended on.
After some investigation, I found out that the error handler isn't even called reliably:
* When `onRequestAbort` hook is registered, the error handler is called
* When `onRequestAbort` hook isn't registered, the error handler is never called
Additionally, the error passed to the error handler is not `instanceof Error` and doesn't have a `statusCode` property, unlike indicated by TypeScript types for `FastifyError`, which the parameter is. In fact, the error given is the response object returned from the route handler. This poses a problem for us because we're logging errors, but the response objects can contain sensitive data, which we don't want to log.
### Steps to Reproduce
Code sample for reproduction:
```js
import { fastify } from 'fastify'
import net from 'node:net'
import { setTimeout } from 'node:timers/promises'
const app = fastify()
app.setErrorHandler(async (error, request, reply) => {
console.log(error, error instanceof Error, error.statusCode)
})
app.get('/', async (req) => {
console.log('receive start', req.id, req.raw.destroyed)
await setTimeout(500)
console.log('receive end', req.id, req.raw.destroyed)
return { hello: 'world' }
})
// Comment out the following line, the error handler will not be invoked
app.addHook('onRequestAbort', async (req) => console.log('abort', req.id))
await app.listen({ port: 0 })
const socket = net.connect(app.server.address().port)
socket.write('GET / HTTP/1.1\r\nHost: example.com\r\n\r\n')
await setTimeout(200)
socket.destroy()
await setTimeout(1000)
await app.close()
```
When invoked as stated above, the output is:
```
> node index.js
receive start req-1 false
abort req-1
receive end req-1 true
{ hello: 'world' } false undefined
```
With the line commented out:
```
> node index.js
receive start req-1 false
receive end req-1 true
```
### Expected Behavior
Preferrably, I wouldn't want aborted requests be considered errors, even when a response is sent (i.e. revert #4611). But I do understand the intent of that PR, so if it's not an option, I'd expect the following:
* Call the error handler no matter if `onRequestAbort` hook is registered
* Pass an instance of `FastifyError` to the error handler, with a generic error message, instead of the response body | https://github.com/fastify/fastify/issues/4626 | https://github.com/fastify/fastify/pull/4631 | ca9785a3fadd9050ec163c6a0841a06f387a71c6 | da9ace5ef2f5828bc71a2e54af9fdc4107e1258d | "2023-03-13T22:02:45Z" | javascript | "2023-03-20T08:54:26Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 4,590 | [".github/workflows/package-manager-ci.yml", "docs/Reference/LTS.md"] | Updated github actions environments to ubuntu-22.04 | Currently our runners are giving this warning:
> The ubuntu-18.04 environment is deprecated, consider switching to ubuntu-20.04(ubuntu-latest), or ubuntu-22.04 instead. For more details see https://github.com/actions/virtual-environments/issues/6002
| https://github.com/fastify/fastify/issues/4590 | https://github.com/fastify/fastify/pull/4591 | 7cbad5819738183226184950259934de8ea90a2b | dd2a88587b8d0372a66ac5289dda55877e58b887 | "2023-02-22T11:38:35Z" | javascript | "2023-02-22T12:25:14Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 4,592 | ["lib/error-handler.js", "lib/errors.js", "test/schema-serialization.test.js", "types/errors.d.ts"] | JSON schema validation returns wrong missing field on nested objects | ### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the bug has not already been reported
### Fastify version
4.0.0
### Plugin version
_No response_
### Node.js version
18.14.1
### Operating system
macOS
### Operating system version (i.e. 20.04, 11.3, 10)
Ventura 13.2.1
### Description
I'm using the following validation schema for my response:
```
const responseSchema = {
type: "object",
required: ["ok", "data", "message"],
properties: {
ok: {
type: "boolean",
},
data: {
type: "object",
required: ["token"],
properties: {
token: {
type: "string",
nullable: true,
},
},
},
message: {
type: "string",
},
},
};
export const getSchema: RouteShorthandOptions = {
schema: {
response: {
200: responseSchema,
500: responseSchema,
},
},
};
```
When trying to send the following response in my endpoint:
```
return rep.status(500).send({
ok: false,
data: {},
message: "Access Token creation failed.",
});
```
It correctly fails because token is not present, but instead of showing the token field it returns the ok field:
```
{
"statusCode": 500,
"error": "Internal Server Error",
"message": "\"ok\" is required!"
}
```
It is basically returning the first field that finds in an array of required elements which corresponds to the parent object (`ok` field), instead of returning the specific field that is failing validation (`token`).
Trying Fastify for the first time and so far the experience is great, just found out this little issue, thanks!
### Steps to Reproduce
Copy-paste the schema provided in the description pass it to the endpoint and hit it with Postman or curl.
### Expected Behavior
Should return the name of the field that is failing the validation. | https://github.com/fastify/fastify/issues/4592 | https://github.com/fastify/fastify/pull/4601 | b8ae90a419775a922cb10bc889599aaae415e8bc | d74b2b4371d176446108ec798a3672c0b389ae60 | "2023-02-22T00:49:11Z" | javascript | "2023-02-26T20:33:21Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 4,575 | ["docs/Reference/Reply.md", "docs/Reference/Warnings.md", "lib/reply.js", "lib/warnings.js", "test/internals/reply.test.js", "test/types/reply.test-d.ts", "types/reply.d.ts"] | Proposed updates to the reply.getResponseTime() documentation | ### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the feature has not already been requested
### 🚀 Feature Proposal
The `.getResponseTime()` portion of the docs states `Note that unless this function is called in the [onResponse hook](https://www.fastify.io/docs/latest/Reference/Hooks#onresponse) it will always return 0.`. However, I've tested it with `onResponse` and it doesn't return 0, it returns a very small number. This behaviour is expected, but is not represented in the docs.
I'd also like to add something to say that if you'd like to record route response time metrics, this is the place to do it.
What are your thoughts?
Reference: https://www.fastify.io/docs/latest/Reference/Reply/#getresponsetime
### Motivation
Improve documentation & show how easy it is to response response time reliably (much harder in other frameworks)
### Example
Note: To measure the ensure request response time, the function must be called in a `onResponse` hook. Calling the function in other hooks will result in `0` or very low numbers that do not represent the entire request response time.
If you would like to record request response time metrics, the result of `.getResponseTime()` in a `onResponse` hook is the recommended way to do that. | https://github.com/fastify/fastify/issues/4575 | https://github.com/fastify/fastify/pull/5263 | eca6312d7d9f584bfc6943998f13d3724c8a3f5b | 9c47812e6b19e5f28dc886ad4463fdec5f89e030 | "2023-02-08T21:54:43Z" | javascript | "2024-01-14T19:21:34Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 4,535 | ["docs/Reference/Server.md", "fastify.d.ts", "fastify.js", "lib/server.js", "test/client-timeout.test.js", "test/types/fastify.test-d.ts"] | requestTimeout returns 400 "Bad Client" on request timeout | ### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the bug has not already been reported
### Fastify version
4.12.0
### Plugin version
_No response_
### Node.js version
16.15.0
### Operating system
Linux
### Operating system version (i.e. 20.04, 11.3, 10)
Fedora 36
### Description
When requestTimeout is set on fastify instance and a request is timed out, error 400 "Bad Client" is automaticly sent to client.
### Steps to Reproduce
Set requestTimeout to something low on a fastify instance and make a simple get endpoint which sleeps for a while then returns.
### Example fastify instance
```
// CommonJs
const fastify = require("fastify")({
logger: true,
requestTimeout: 2
});
fastify.get("/", async (request, reply) => {
await new Promise((resolve) => setTimeout(resolve, 5 * 1000));
return { hello: "world" };
});
const start = async () => {
try {
await fastify.listen({ port: 1111 });
} catch (err) {
fastify.log.error(err);
process.exit(1);
}
};
start();
```
### Endpoint response:
```
{"error":"Bad Request","message":"Client Error","statusCode":400}
```
### Expected Behavior
Expected error 408 (Request Timeout). | https://github.com/fastify/fastify/issues/4535 | https://github.com/fastify/fastify/pull/4552 | d14a10fed5f30cf4a14576b9b5994b7c34d9f9b8 | d4a9851e370b9db7f1a605b0ffc26fc1ae9d6446 | "2023-01-26T09:39:58Z" | javascript | "2023-02-09T12:48:50Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 4,511 | ["lib/symbols.js"] | preParsing is undefined not null | fastify version v4.11
"@fastify/cors": "8.2.0",
"@fastify/csrf-protection": "6.1.0",
"@fastify/swagger": "8.2.1",
"@fastify/swagger-ui": "^1.3.0",
"body-parser": "1.20.1",
"cos-nodejs-sdk-v5": "2.11.19",
"cron": "2.2.0",
"fastify": "4.11.0",
"fastify-file-upload": "4.0.0",
"fastify-plugin": "4.4.0",
![1673539895600](https://user-images.githubusercontent.com/37258529/212120665-01b710b1-57e3-4f2b-abdd-7fc1ed78d49d.jpg)
<img width="540" alt="1673539789448" src="https://user-images.githubusercontent.com/37258529/212120671-6d79646d-37ac-4c06-99f6-fabbf8b2a7af.png">
<img width="761" alt="1673539770559" src="https://user-images.githubusercontent.com/37258529/212120680-bf988ec4-551a-4384-a660-87f079e8d3cd.png">
| https://github.com/fastify/fastify/issues/4511 | https://github.com/fastify/fastify/pull/4608 | ec173331c76b8cb31baa5d8764cee9f4f9b6421c | 5a288bc42ad698e63f054a95259ac0d279db5747 | "2023-01-12T16:16:09Z" | javascript | "2023-03-03T10:49:45Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 4,501 | ["docs/Guides/Migration-Guide-V4.md"] | Error handler has 200 as reply status code instead of 500 | ### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the bug has not already been reported
### Fastify version
4.11.0
### Plugin version
_No response_
### Node.js version
18.5.0
### Operating system
Windows
### Operating system version (i.e. 20.04, 11.3, 10)
10
### Description
`setErrorHandler(err,req,reply)` returns 200 as `reply.statusCode` instead of 500.
I'd expect that if an API breaks due to unexpected error, the error handler reply status code should be 500.
**This feature has changed from fastify 3 to fastify 4 (just tested it) because on Fastify 3 it correctly returns 500.**
### Steps to Reproduce
```
import fastify from 'fastify';
const app = fastify();
app.setErrorHandler((error, request, response) => {
console.log(error, error.statusCode, response.statusCode);
response.status(response.statusCode).send({ error: error.message })
})
app.get('/', (request, reply) => {
const m = structuredClone(request);
})
await app.listen({ host: '0.0.0.0', port: 8080 })
```
### Expected Behavior
Expected behavior is to have `reply.statusCode` equal to 500 instead of 200 | https://github.com/fastify/fastify/issues/4501 | https://github.com/fastify/fastify/pull/4503 | 687459a0664619b843630b2cf9726b42b798c3ca | da047e62d6e4cd419f44996f415d87a8a2a14661 | "2023-01-05T21:35:33Z" | javascript | "2023-01-06T21:15:17Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 4,495 | ["lib/contentTypeParser.js", "test/content-parser.test.js"] | ContentTypeParser Image regrex failed to capture any image type when router added | ### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the bug has not already been reported
### Fastify version
4.11.0
### Plugin version
_No response_
### Node.js version
19.x
### Operating system
Linux
### Operating system version (i.e. 20.04, 11.3, 10)
linux mint
### Description
I try to add custom parser to parse all image files.
I copy image content parser code from fastify documentation but fail to capture any image format.
This code throw error:
`FastifyError: Unsupported Media Type: image/jpeg\n at ContentTypeParser.run`.
```js
fastify.addContentTypeParser(/^image\/.*/, { parseAs: "buffer" }, (req, payload, done) => {
done(null, payload)
});
```
But when i remove regrex and add hardcoded image format then no error thrown and image parsed successfully.
This code work:
```js
fastify.addContentTypeParser("image/png", { parseAs: "buffer" }, (req, payload, done) => {
done(null, payload)
});
```
### Steps to Reproduce
```js
fastify.addContentTypeParser(/^image\/.*/, { parseAs: "buffer" }, (req, payload, done) => {
done(null, payload);
});
```
### Expected Behavior
I want to capture all image mime type format.
Suggested regrex must work. | https://github.com/fastify/fastify/issues/4495 | https://github.com/fastify/fastify/pull/4496 | d89b4f4e39a1df21a320f22d11ac62a24c0aef15 | 687459a0664619b843630b2cf9726b42b798c3ca | "2023-01-03T20:54:30Z" | javascript | "2023-01-05T11:23:20Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 4,482 | ["lib/contentTypeParser.js", "test/content-parser.test.js"] | ContentTypeParser.remove, does not throw if parser does not exist | ### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the issue has not already been raised
### Issue
I find it quite inconsequent, if the remove method of ContentTypeParser in case it is not a string or RegExp throws a FST_ERR_CTP_INVALID_TYPE-error but not an Error if there is no parser matching the contentType.
Imho the else case of this if-condition should throw an Error
https://github.com/fastify/fastify/blob/897360ad9a01340b45d94f001d8c46aeee22581f/lib/contentTypeParser.js#L152 | https://github.com/fastify/fastify/issues/4482 | https://github.com/fastify/fastify/pull/4550 | 19d05b542a46bb1f580ef95c9cf258db0be8aa35 | 2179f835706fb804a3e78edf6aa2e2ff4f7ba91f | "2022-12-24T14:07:25Z" | javascript | "2023-02-05T06:31:03Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 4,439 | ["docs/Reference/Request.md", "lib/request.js", "lib/warnings.js", "test/request.deprecated.test.js", "test/router-options.test.js"] | Access handler name | ### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the feature has not already been requested
### 🚀 Feature Proposal
Open Telemetry accesses the (now deprecated via #4216) `request.context` property so it can try to get the name of the handler function. See https://github.com/open-telemetry/opentelemetry-js-contrib/blob/4cafe6becc19cfb76c53393cb03a5c0574a68b0d/plugins/node/opentelemetry-instrumentation-fastify/src/instrumentation.ts#L264-L268
With `request.context` deprecated, we now get a big deprecation warning printed every the app gets its first request. Would it be possible to expose this information in a meaningful way?
There's an issue in their repo as well: https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1275
### Motivation
It's useful to get the name of a handler function as a span name in traces.
### Example
Would replace `request.context.handler.name` | https://github.com/fastify/fastify/issues/4439 | https://github.com/fastify/fastify/pull/4470 | 7053ea7756bf05d9b7049342045a6e79d9c0351c | 59050e57458274cdaa038cd50a387cf28e18dd8a | "2022-11-25T08:55:21Z" | javascript | "2023-09-04T10:09:35Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 4,435 | ["test/types/register.test-d.ts", "types/plugin.d.ts", "types/register.d.ts"] | Wrong types for FastifyRegister with custom logger | ### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the bug has not already been reported
### Fastify version
4.10.0
### Plugin version
_No response_
### Node.js version
18.12.0
### Operating system
macOS
### Operating system version (i.e. 20.04, 11.3, 10)
12.6.1
### Description
We're using a custom logger (based on Pino) in our implementation. When using `withTypeProvider`, we're having some issues with Typescript and the registration of plugins / routes.
If I understand correctly, [FastifyRegister](https://github.com/fastify/fastify/blob/45c8564e6cff193763c4fe0616d103405e353e18/types/register.d.ts#L20) does not use the generic for the logger, hence we're not able to pass the custom instance inside the register function.
<img width="1086" alt="image" src="https://user-images.githubusercontent.com/2797489/203072319-42adfd83-549f-4ad4-9cb9-6f1fc0bcfd8c.png">
### Steps to Reproduce
```ts
import { TypeBoxTypeProvider } from "@fastify/type-provider-typebox";
import { fastify } from "fastify";
import { pino } from "pino";
const server = fastify({
logger: pino(),
}).withTypeProvider<TypeBoxTypeProvider>();
type AppFastifyInstance = typeof server;
const routes = async (instance: AppFastifyInstance): Promise<void> => {
instance.get("/bar", {}, async (res, reply) => {
return reply.send("ok");
});
};
/** "routes" goes in error */
await server.register(routes, {
prefix: "/foo",
});
```
### Expected Behavior
It should work :) | https://github.com/fastify/fastify/issues/4435 | https://github.com/fastify/fastify/pull/4436 | 311590c147af90e32f7bcbcc10e0d176cbbafaca | df5d94f541c50f690e8beebd143fdb3d861d991b | "2022-11-21T13:57:05Z" | javascript | "2022-11-26T20:07:39Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 4,430 | ["test/types/logger.test-d.ts", "types/logger.d.ts"] | Typescript: logLevel type definition in RouteShorthandOptions does not include 'silent' option | ### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the bug has not already been reported
### Fastify version
4.9.2
### Plugin version
_No response_
### Node.js version
16.15.0
### Operating system
macOS
### Operating system version (i.e. 20.04, 11.3, 10)
12.6
### Description
Pino documentation states that in order to turn off the logging for a certain route, one should set `{logLevel: 'silent'} in the route options.
This works well, however it doesn't play nice with Typescript. It happens because `logLevel` property in `RouteShorthandOptions` interface uses an alias for `pino.Level`, instead of `pino.LevelWithSilent` as its type - https://github.com/fastify/fastify/blob/9c1be2ab56cca0125b48666241dc4ff5338b69d8/types/logger.d.ts#L16
### Steps to Reproduce
```ts
fastify.get('/your-route', { logLevel: 'silent' }, (request, reply) => {
reply.send({ hello: 'world' })
})
```
will give you `TS2322: Type '"silent"' is not assignable to type 'Level | undefined'.`
### Expected Behavior
no TS error should occur | https://github.com/fastify/fastify/issues/4430 | https://github.com/fastify/fastify/pull/4432 | 9c1be2ab56cca0125b48666241dc4ff5338b69d8 | a8873ef924d51e84549facf63cf1153f8521362b | "2022-11-20T21:03:19Z" | javascript | "2022-11-21T14:33:51Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 4,376 | ["docs/Reference/Hooks.md", "test/route-hooks.test.js", "test/types/hooks.test-d.ts", "test/types/route.test-d.ts", "test/types/type-provider.test-d.ts", "types/route.d.ts"] | Wrong typings for hooks on route options | The in the snippet below, the hook types are a union of two identical types like `onRequestHookHandler<...> | onRequestHookHandler<...>` etc, and this excludes the async hook type, which should be valid to use here, right?
Are these supposed to be <code>onRequestHookHandler<...> | onRequest<em><b>Async</b></em>HookHandler<...></code>, etc?
https://github.com/fastify/fastify/blob/5c75f4993255a7e3fc5afbdc4b8171be52ecb618/types/route.d.ts#L48-L56 | https://github.com/fastify/fastify/issues/4376 | https://github.com/fastify/fastify/pull/4655 | 12914de76a98f2f71d4cc4ba8786d0fb4cd73823 | 4c02647b790b955e463e08da9811d501e666b227 | "2022-10-26T07:09:26Z" | javascript | "2023-04-10T07:50:38Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 4,375 | ["docs/Reference/Request.md", "lib/context.js", "lib/request.js", "lib/route.js", "test/bodyLimit.test.js", "test/request-error.test.js", "test/types/request.test-d.ts", "types/request.d.ts"] | Request bodyLimit | Right now, you can set the `bodyLimit` in two ways:
```
const app = Fastify({ bodyLimit: serverLimit })
app.post('/route-limit', {
bodyLimit: routeLimit,
handler (req) { return req.rawBody }
})
```
A custom `ContentTypeParser` or a `preParsing` hook function:
- can access the `serverLimit` via `app.initialConfig.bodyLimit`
- can't access the `routeLimit` unless a private API `request.context._parserOptions.limit`
I think we should add a getter `request.routeBodyLimit` that returns the custom `routeLimit || serverLimit`
WDYT?
Ref https://github.com/Eomm/fastify-raw-body/issues/35
| https://github.com/fastify/fastify/issues/4375 | https://github.com/fastify/fastify/pull/4397 | de53fba42a664af05f1492564f5a71427135a55b | f1bd80e007b019a2708c5fc1ff8340b0082908e7 | "2022-10-26T06:36:01Z" | javascript | "2022-11-05T21:02:04Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 4,356 | ["lib/hooks.js", "lib/route.js", "test/hooks.test.js", "test/internals/hooks.test.js"] | Improve error message for hooks check | `instead got object` is weird - better to check for `null` and print that? or `util.inspect` perhaps
_Originally posted by @SimenB in https://github.com/fastify/fastify/pull/4351#discussion_r997819390_
| https://github.com/fastify/fastify/issues/4356 | https://github.com/fastify/fastify/pull/4387 | e9604ce3af7a6a846bdbca1d20a93dc7e5a51401 | a71dd83cc65c79c2a01dfbe91f8ee64fec3c0509 | "2022-10-18T07:43:40Z" | javascript | "2022-10-31T17:34:07Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 4,354 | ["test/logger.test.js", "test/types/logger.test-d.ts", "test/types/request.test-d.ts", "types/hooks.d.ts", "types/instance.d.ts", "types/logger.d.ts", "types/plugin.d.ts", "types/reply.d.ts", "types/request.d.ts", "types/route.d.ts"] | TypeScript issue while running Fastify TS code after upgrading to 4.9.1 | ### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the regression has not already been reported
### Last working version
4.9.0
### Stopped working in version
4.9.1
### Node.js version
16
### Operating system
Windows
### Operating system version (i.e. 20.04, 11.3, 10)
11
### 💥 Regression Report
```
src/App.ts(13,11): error TS2322: Type 'FastifyInstance<RawServerDefault, IncomingMessage, ServerResponse<IncomingMessage>, FastifyBaseLogger<FastifyBaseLogger<any>>, FastifyTypeProviderDefault> & PromiseLike<...>' is not assignable to type 'FastifyInstance<RawServerDefault, IncomingMessage, ServerResponse<IncomingMessage>, DefaultFastifyLogger, FastifyTypeProviderDefault>'.
Types of property 'log' are incompatible.
Property 'setBindings' is missing in type 'FastifyBaseLogger<FastifyBaseLogger<any>>' but required in type 'DefaultFastifyLogger'.
```
Got the compilation error after upgrading to 4.9.1, but it should not be a breaking change. I expected this release to be backward compatible.
Here is the configuration of the logger;
```TypeScript
logger: {
name: 'PICO',
base: null,
redact: {
paths: ['systemId', 'timestamp'],
remove: true
}
},
disableRequestLogging: true
```
### Steps to Reproduce
Just create basic fastify instance, specify logger without above mentioned binding and run it through `ts-node`
### Expected Behavior
The app should run without specifying any setBindings if not needed. | https://github.com/fastify/fastify/issues/4354 | https://github.com/fastify/fastify/pull/4355 | fe3cf0e6985015a6498de34290aa905fbd245597 | d0d36964373b1c54d30a4e8de661da6ad186cc76 | "2022-10-17T23:33:25Z" | javascript | "2022-10-18T07:12:41Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 4,347 | ["test/types/request.test-d.ts", "types/context.d.ts", "types/request.d.ts"] | missing types for request.routeConfig | ### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the bug has not already been reported
### Fastify version
4.9.0
### Plugin version
_No response_
### Node.js version
any
### Operating system
Windows
### Operating system version (i.e. 20.04, 11.3, 10)
11
### Description
Even though fastify reports `request.context.config` as deprecated and recommends using `Request#routeConfig` or `Request#routeSchema` instead, deprecated field has TS types for it, while neither of the recommended options do.
Is this simply an oversight in types, or am I missing something? If routeConfig and routeSchema are supposed to have exactly same types that `context.config` had, I can send in a fix PR.
### Steps to Reproduce
Try to access `request.routeConfig` or `request.routeSchema` from TS file.
### Expected Behavior
There are valid types for recommended usage | https://github.com/fastify/fastify/issues/4347 | https://github.com/fastify/fastify/pull/4352 | 79107281bf096ca6d56262b5920d9f2eda7a33a2 | fe3cf0e6985015a6498de34290aa905fbd245597 | "2022-10-17T09:48:41Z" | javascript | "2022-10-17T19:17:43Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 4,344 | ["test/logger.test.js", "test/types/logger.test-d.ts", "test/types/request.test-d.ts", "types/hooks.d.ts", "types/instance.d.ts", "types/logger.d.ts", "types/plugin.d.ts", "types/reply.d.ts", "types/request.d.ts", "types/route.d.ts"] | setBindings is no longer available on the typing of FastifyBaseLogger | ### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the regression has not already been reported
### Last working version
4.3.0
### Stopped working in version
4.8.1
### Node.js version
18.x
### Operating system
Linux
### Operating system version (i.e. 20.04, 11.3, 10)
20.04
### 💥 Regression Report
FastifyLoggerInstance had a method called setBindings that I am using currently to preserve context across multiple log method calls. It looks like FastifyLoggerInstance was replaced with FastifyBaseLogger in https://github.com/fastify/fastify/pull/4224, but the typings (at least) show the method as missing when my typecheck runs in my CI checks:
```
// tsc --noEmit
> tsc --noEmit
src/_framework/context-from-params.ts:41:14 - error TS2339: Property 'setBindings' does not exist on type 'FastifyBaseLogger'.
41 state.log.setBindings(metadata);
~~~~~~~~~~~
src/_framework/context-from-request.ts:31:[16](<redacted>/actions/runs/3227392130/jobs/5282140045#step:5:17) - error TS2339: Property 'setBindings' does not exist on type 'FastifyBaseLogger'.
31 request.log.setBindings(metadata);
~~~~~~~~~~~
Found 2 errors in 2 files.
```
### Steps to Reproduce
Sorry that I cannot link to the project, but I think if you have a default simple fastify project that calls `request.log.setBindings()` in 4.3 and upgrade it to 4.8, the type checking should fail with a similar error as above.
### Expected Behavior
I would expect that this method would be preserved in source code and types unless there was a major version change. | https://github.com/fastify/fastify/issues/4344 | https://github.com/fastify/fastify/pull/4346 | 37c24267e24a5696fe74e4c140fccee629a6f8f2 | 846885f2b3622ca91c94ee3d357047340aeb2d64 | "2022-10-17T02:34:40Z" | javascript | "2022-10-17T10:11:47Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 4,342 | ["docs/Guides/Write-Type-Provider.md", "test/types/type-provider.test-d.ts"] | Instances with type-providers are not assignable to `FastifyInstance` | ### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the bug has not already been reported
### Fastify version
4.7.0
### Plugin version
_No response_
### Node.js version
18.1.0
### Operating system
Linux
### Operating system version (i.e. 20.04, 11.3, 10)
Ubuntu 20.04.5 LTS
### Description
Fastify instances with an enabled type-provider are not subtypes of the base `FastifyInstance` interface.
## Example
A fastify server with type-providers enabled will not be usable as input for the `@fastify/aws-lambda` plugin, which expects a `FastifyInstance` parameter.
```ts
export default function awsLambdaFastify<TEvent, TResult = LambdaResponse>(
app: FastifyInstance,
options?: LambdaFastifyOptions
): PromiseHandler<TEvent, TResult>;
```
## Cause
A more detailed explanation can be found in the [reproduction repo](https://github.com/driimus/fastify-instance-assignability#cause).
In short, the assignability issue stems from certain methods of `FastifyInstance` being contravariant on `TypeProvider`. Because of that, the compiler has to flip the assignability check's direction, which boils down to the following outcome:
```diff
Types of property 'handler' are incompatible.
Type 'RouteHandlerMethod<Server<typeof IncomingMessage, typeof ServerResponse>, IncomingMessage, ServerResponse<IncomingMessage>, ... 4 more ..., FastifyBaseLogger>' is not assignable to type 'RouteHandlerMethod<RawServerDefault, IncomingMessage, ServerResponse<IncomingMessage>, any, any, any, FastifyTypeProviderDefault, FastifyBaseLogger>'.
Types of parameters 'request' and 'request' are incompatible.
Type 'FastifyRequest<any, RawServerDefault, IncomingMessage, any, FastifyTypeProviderDefault, any, FastifyBaseLogger, ResolveFastifyRequestType<...>>' is not assignable to type 'FastifyRequest<any, Server<typeof IncomingMessage, typeof ServerResponse>, IncomingMessage, any, TypeBoxTypeProvider, any, FastifyBaseLogger, ResolveFastifyRequestType<...>>'.
Type 'ResolveFastifyRequestType<FastifyTypeProviderDefault, any, any>' is not assignable to type 'ResolveFastifyRequestType<TypeBoxTypeProvider, any, any>'.
+ Type 'FastifyTypeProviderDefault' is not assignable to type 'TypeBoxTypeProvider'.
```
### Steps to Reproduce
1. Check out the [Minimal reproduction repo](https://github.com/driimus/fastify-instance-assignability), which uses the `"@fastify/aws-lambda": "^3.1.3"` plugin.
1. Install dependencies
1. Run `pnpm tsc --noEmit` to check for type errors
1. Notice the assignability error
From the CI run: https://github.com/driimus/fastify-instance-assignability/actions/runs/3259362782/jobs/5352129645#step:6:11
```
Error: src/index.ts([27](https://github.com/driimus/fastify-instance-assignability/actions/runs/3259362782/jobs/5352129645#step:6:28),41): error TS2769: No overload matches this call.
Overload 1 of 2, '(app: FastifyInstance<RawServerDefault, IncomingMessage, ServerResponse<IncomingMessage>, FastifyBaseLogger, FastifyTypeProviderDefault>, options?: LambdaFastifyOptions | undefined): PromiseHandler<...>', gave the following error.
Argument of type 'FastifyInstance<Server<typeof IncomingMessage, typeof ServerResponse>, IncomingMessage, ServerResponse<IncomingMessage>, FastifyBaseLogger, TypeBoxTypeProvider>' is not assignable to parameter of type 'FastifyInstance<RawServerDefault, IncomingMessage, ServerResponse<IncomingMessage>, FastifyBaseLogger, FastifyTypeProviderDefault>'.
The types returned by 'after()' are incompatible between these types.
Type 'FastifyInstance<Server<typeof IncomingMessage, typeof ServerResponse>, IncomingMessage, ServerResponse<IncomingMessage>, FastifyBaseLogger, TypeBoxTypeProvider> & PromiseLike<...>' is not assignable to type 'FastifyInstance<RawServerDefault, IncomingMessage, ServerResponse<IncomingMessage>, FastifyBaseLogger, FastifyTypeProviderDefault> & PromiseLike<...>'.
Type 'FastifyInstance<Server<typeof IncomingMessage, typeof ServerResponse>, IncomingMessage, ServerResponse<IncomingMessage>, FastifyBaseLogger, TypeBoxTypeProvider> & PromiseLike<...>' is not assignable to type 'FastifyInstance<RawServerDefault, IncomingMessage, ServerResponse<IncomingMessage>, FastifyBaseLogger, FastifyTypeProviderDefault>'.
Types of property 'register' are incompatible.
Type 'FastifyRegister<FastifyInstance<Server<typeof IncomingMessage, typeof ServerResponse>, IncomingMessage, ServerResponse<IncomingMessage>, FastifyBaseLogger, TypeBoxTypeProvider> & PromiseLike<...>, RawServerDefault, FastifyTypeProvider>' is not assignable to type 'FastifyRegister<FastifyInstance<RawServerDefault, IncomingMessage, ServerResponse<IncomingMessage>, FastifyBaseLogger, FastifyTypeProviderDefault> & PromiseLike<...>, RawServerDefault, FastifyTypeProvider>'.
Type 'FastifyInstance<Server<typeof IncomingMessage, typeof ServerResponse>, IncomingMessage, ServerResponse<IncomingMessage>, FastifyBaseLogger, TypeBoxTypeProvider> & PromiseLike<...>' is not assignable to type 'FastifyInstance<RawServerDefault, IncomingMessage, ServerResponse<IncomingMessage>, FastifyBaseLogger, FastifyTypeProviderDefault> & PromiseLike<...>'.
Type 'FastifyInstance<Server<typeof IncomingMessage, typeof ServerResponse>, IncomingMessage, ServerResponse<IncomingMessage>, FastifyBaseLogger, TypeBoxTypeProvider> & PromiseLike<...>' is not assignable to type 'FastifyInstance<RawServerDefault, IncomingMessage, ServerResponse<IncomingMessage>, FastifyBaseLogger, FastifyTypeProviderDefault>'.
The types of 'addSchema(...).addHook' are incompatible between these types.
Type '{ <RouteGeneric extends import("/home/runner/work/fastify-instance-assignability/fastify-instance-assignability/node_modules/.pnpm/[email protected]/node_modules/fastify/types/route").RouteGenericInterface = import("/home/runner/work/fastify-instance-assignability/fastify-instance-assignability/node_modules/.pnpm/fastif...' is not assignable to type '{ <RouteGeneric extends import("/home/runner/work/fastify-instance-assignability/fastify-instance-assignability/node_modules/.pnpm/[email protected]/node_modules/fastify/types/route").RouteGenericInterface = import("/home/runner/work/fastify-instance-assignability/fastify-instance-assignability/node_modules/.pnpm/fastif...'. Two different types with this name exist, but they are unrelated.
Types of parameters 'hook' and 'hook' are incompatible.
Types of parameters 'opts' and 'opts' are incompatible.
Type 'RouteOptions<Server<typeof IncomingMessage, typeof ServerResponse>, IncomingMessage, ServerResponse<IncomingMessage>, ... 4 more ..., FastifyBaseLogger> & { ...; }' is not assignable to type 'RouteOptions<RawServerDefault, IncomingMessage, ServerResponse<IncomingMessage>, any, any, any, FastifyTypeProviderDefault, FastifyBaseLogger> & { ...; }'.
Type 'RouteOptions<Server<typeof IncomingMessage, typeof ServerResponse>, IncomingMessage, ServerResponse<IncomingMessage>, ... 4 more ..., FastifyBaseLogger> & { ...; }' is not assignable to type 'RouteOptions<RawServerDefault, IncomingMessage, ServerResponse<IncomingMessage>, any, any, any, FastifyTypeProviderDefault, FastifyBaseLogger>'.
Types of property 'handler' are incompatible.
Type 'RouteHandlerMethod<Server<typeof IncomingMessage, typeof ServerResponse>, IncomingMessage, ServerResponse<IncomingMessage>, ... 4 more ..., FastifyBaseLogger>' is not assignable to type 'RouteHandlerMethod<RawServerDefault, IncomingMessage, ServerResponse<IncomingMessage>, any, any, any, FastifyTypeProviderDefault, FastifyBaseLogger>'.
Types of parameters 'request' and 'request' are incompatible.
Type 'FastifyRequest<any, RawServerDefault, IncomingMessage, any, FastifyTypeProviderDefault, any, FastifyBaseLogger, ResolveFastifyRequestType<...>>' is not assignable to type 'FastifyRequest<any, Server<typeof IncomingMessage, typeof ServerResponse>, IncomingMessage, any, TypeBoxTypeProvider, any, FastifyBaseLogger, ResolveFastifyRequestType<...>>'.
Type 'ResolveFastifyRequestType<FastifyTypeProviderDefault, any, any>' is not assignable to type 'ResolveFastifyRequestType<TypeBoxTypeProvider, any, any>'.
Type 'FastifyTypeProviderDefault' is not assignable to type 'TypeBoxTypeProvider'.
Overload 2 of 2, '(app: FastifyInstance<RawServerDefault, IncomingMessage, ServerResponse<IncomingMessage>, FastifyBaseLogger, FastifyTypeProviderDefault>, options?: LambdaFastifyOptions | undefined): CallbackHandler<...>', gave the following error.
Argument of type 'FastifyInstance<Server<typeof IncomingMessage, typeof ServerResponse>, IncomingMessage, ServerResponse<IncomingMessage>, FastifyBaseLogger, TypeBoxTypeProvider>' is not assignable to parameter of type 'FastifyInstance<RawServerDefault, IncomingMessage, ServerResponse<IncomingMessage>, FastifyBaseLogger, FastifyTypeProviderDefault>'.
```
### Expected Behavior
I would expect specialised versions of the `FastifyInstance` interface, such as the ones using a custom type provider, to be assignable to `FastifyInstance`.
I am aware of some available workarounds:
1. Extracting the type-provider enabled instance into a separate reference (similar to the [scoped type-provider](https://www.fastify.io/docs/latest/Reference/Type-Providers/#scoped-type-provider) docs suggestion).
1. Extending affected function signatures to include generic parameters which are propagated to their input argument of type `FastifyInstance`.
However, both of them seem inferior to ensuring that subtypes of `FastifyInstance` are assignable to the base interface.
I haven't look at the way type providers are being used in details, but it seems possible: https://github.com/fastify/fastify/compare/77b7582...driimus:fastify:test/type-provider-contravariance | https://github.com/fastify/fastify/issues/4342 | https://github.com/fastify/fastify/pull/4371 | 65d1a3268d48bb24236d8ad26946255a324658a3 | 31972aaf557b7dada511b9a306ae9d31101c7e34 | "2022-10-16T13:28:21Z" | javascript | "2022-10-26T18:15:27Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 4,327 | ["lib/error-handler.js", "test/content-type.test.js"] | Uncaught exception in error handler | ### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the bug has not already been reported
### Fastify version
4.6.0
### Plugin version
_No response_
### Node.js version
16.6.x
### Operating system
macOS
### Operating system version (i.e. 20.04, 11.3, 10)
20
### Description
I was working on a plugin, one that creates a db transaction once a request starts/ends
and come across an issue where fastify process is killed.
In the example I added, sending a request to "/bug" cause the process to exit.
When there is a custom error handler, and an exception occurs within a hook
fastify will call the custom error handler, creating a new "payload", which will kill the process and print:
```
Attempted to send payload of invalid type 'object'. Expected a string or Buffer.
```
### Steps to Reproduce
```js
const Fastify = require("fastify");
const fastify = Fastify({
logger: true,
disableRequestLogging: true,
});
fastify.setErrorHandler(async (error, request, reply) => {
// Look mom, i'm a teapot.
return reply.status(418).send({
iam: "a teapot",
});
});
fastify.register(async () => {
fastify.decorateRequest("commitTransaction", true);
fastify.addHook("onError", async (request) => {
request.commitTransaction = false;
});
fastify.addHook("onSend", async (request, reply, payload) => {
if (request.commitTransaction) {
throw new Error("some exception");
}
return payload;
});
});
fastify.post("/bug", async (request, reply) => {
return reply.send("test");
});
fastify.post("/working", async (request, reply) => {
return reply.send({ test: 1 });
});
return fastify.listen({ host: "127.0.0.1", port: 3333 });
```
### Expected Behavior
1. The process should not die.
2. Calling an error handler, and then calling all the lifecycle hooks all over again is weird.
I am used to error handler being the last stop before a reply is sent.
The only way I could make the error handler be the last stop is by using (the under documented) "hijack"
I think fastify is great, but it seems to have fallen into a common trap regrading errors and errors handling.
There are two versions of an "Error", an "exception" and an applicative error.
The "exception" type is the equivalent of a RuntimeExceprion in Java, where shit may hit the fence by null pointer exceptions, or any other stuff the code did not except **and shouldn't have** (if every line of code we wrote checked if something is null or undefined, we would go crazy).
The applicative error type is the equivalent of a checked exception in Java, its used for example when
schema validation fails. Point is, this is an error which is used as control flow.
I would argue that exceptions should result in a call to the error handler, which should be the last
one to handle the request chain. | https://github.com/fastify/fastify/issues/4327 | https://github.com/fastify/fastify/pull/4329 | 6b2aff6c6808bdc162b461ce68c025e00c58e878 | 90fb718ea8239e59b3abdf6906fb82554d8cc0db | "2022-10-10T07:53:39Z" | javascript | "2022-10-10T10:37:47Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 4,319 | ["docs/Reference/Hooks.md"] | hasRoute causes infinite loop | ### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the bug has not already been reported
### Fastify version
4.7
### Plugin version
_No response_
### Node.js version
16.14.2
### Operating system
macOS
### Operating system version (i.e. 20.04, 11.3, 10)
12.13.1
### Description
If you want to add a route in an `onRoute` hook function and before you check if this route already exists with the new `hasRoute`method, then you will be stuck in an infinite loop, calling the `onRoute` hook over and over again.
### Steps to Reproduce
```js
const Fastify = require('fastify')
const app = Fastify({ logger: true })
app.addHook('onRoute', function (routeOptions) {
const { url, method } = routeOptions
if (!this.hasRoute({
url,
method,
constraints: {
host: 'fastify.io'
}
})) {
this.route({
url,
method,
constraints: {
host: 'fastify.io'
},
handler: () => {}
})
}
})
app.get('/test', () => {})
```
### Expected Behavior
The `onRoute` hook should be called only one more time for the route added in the hook method. | https://github.com/fastify/fastify/issues/4319 | https://github.com/fastify/fastify/pull/4322 | 62d2c94a26ac619e95e16d99e5d6d2646a60a119 | da7471f1e43822cba2a2b090cd34a54a6e1469dd | "2022-10-03T21:03:58Z" | javascript | "2022-10-06T15:50:32Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 4,271 | ["lib/route.js", "test/route.test.js"] | exposeHeadRoute and manually generated head routes not really distingiushable | ### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the issue has not already been raised
### Issue
The automatically generated Head route (exposeHeadRoute: true) gets in fastify-rate-limit the routelimit hook twice.
I can patch it as you can see https://github.com/fastify/fastify-rate-limit/pull/267 by checking if the exposeHeadRoute is set to true. But this can also mean that if you explicitly set exposeHeadRoute on a head-route to true to also not adding the rateLimit hook to the head-route.
See:
https://github.com/fastify/fastify-rate-limit/blob/93ce1e5ae90ffb92f9030f9e3117980ec9e0606d/test/route-rate-limit.test.js#L1410
So it would be nice that we could make the HEAD-routes generated by exposeHeadRoute detectable. Like adding an additional atrtibute to the routeOptions like autogeneratedRoute or isFastify for expressing that fastify added that route?!
Or we decide that setting exposeHeadRoute on head makes no sense anyway and the linked PR to the plugin is sufficient. Maybe throwing an error if we set exposeHeadRoute on a head-route could also be applicable. | https://github.com/fastify/fastify/issues/4271 | https://github.com/fastify/fastify/pull/4273 | 123753774f0ee6392f41ebc7cce4e790a2a264d9 | 21f209f9ad5205d91e7a520ef380f51b8587419f | "2022-09-14T12:43:55Z" | javascript | "2022-09-14T15:41:16Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 4,267 | ["lib/server.js", "test/listen.deprecated.test.js"] | Variadic listen signature is not working anymore | ### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the regression has not already been reported
### Last working version
3.x
### Stopped working in version
4.x
### Node.js version
16
### Operating system
Linux
### Operating system version (i.e. 20.04, 11.3, 10)
-
### 💥 Regression Report
As per the [blog post](https://medium.com/@fastifyjs/fastify-v4-ga-59f2103b5f0e) (note that this is not mentioned in the migration guide of the docs, just the blog post) the variadic signature of the `listen` method is deprecated.
What I found is that it's actually broken for a fairly simple use case, that of providing the port via an environment variable. I suspect the problem is with the type. If you provide it as a number, it works. When it comes from an environment variable it's a string. This scenario doesn't work anymore.
I would have expected the signature to be deprecated but still work, but in practice this use case no longer works.
### Steps to Reproduce
With this server:
```js
// index.js
import fastify from 'fastify'
const app = fastify({
logger: true
})
app.listen(process.env.PORT, '0.0.0.0')
```
Running with:
```sh
PORT=12345 node index.js
```
Gives (note that it runs on a random port):
```sh
{"level":30,"time":1662976097851,"pid":6028,"hostname":"X86","msg":"Server listening at http://0.0.0.0:63694"}
```
### Expected Behavior
It should be running on the port specified in the PORT environment variable. | https://github.com/fastify/fastify/issues/4267 | https://github.com/fastify/fastify/pull/4269 | c7fdbdec4852ded79a5b46e7f682aae1e6ac7807 | 9bac49db2884f31f71724bf7e43405a3575aa0a8 | "2022-09-12T09:55:09Z" | javascript | "2022-09-12T16:40:46Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 4,259 | ["examples/typescript-server.ts"] | Body validation scheme for ${method}:${path} route is not supported! | ### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the bug has not already been reported
### Fastify version
4.5.3
### Plugin version
_No response_
### Node.js version
16.12.0
### Operating system
Windows
### Operating system version (i.e. 20.04, 11.3, 10)
Windows 10 Home
### Description
throw new Error(`Body validation schema for ${method}:${path} route is not supported!`)
^
Error: Body validation schema for GET:/ping/:bar route is not supported!
### Steps to Reproduce
- take the code from https://github.com/fastify/fastify/blob/main/examples/typescript-server.ts
- compile and run it
- crashes when code is executed
### Expected Behavior
code examples should not have errors.. | https://github.com/fastify/fastify/issues/4259 | https://github.com/fastify/fastify/pull/4261 | 16e4b5bb1dbad1772572d9247694259f2419510e | aa43e2de2cac18d7654c6a88e5437f8b0854872e | "2022-09-08T03:15:54Z" | javascript | "2022-09-10T07:49:00Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 4,256 | [".github/scripts/lint-ecosystem.js"] | Improve ecosystem script check | ### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the bug has not already been reported
### Fastify version
-
### Plugin version
-
### Node.js version
-
### Operating system
macOS
### Operating system version (i.e. 20.04, 11.3, 10)
-
### Description
The script in: https://github.com/fastify/fastify/blob/main/.github/scripts/lint-ecosystem.js
It should trigger an error if there are wrong patterns in the docs.
Example (missing backtick):
```
- [my lib](http://)
```
### Steps to Reproduce
here we merged the wrong items because of the missing backticks
https://github.com/fastify/fastify/pull/4230
### Expected Behavior
_No response_ | https://github.com/fastify/fastify/issues/4256 | https://github.com/fastify/fastify/pull/4257 | 16b25c8fdb0f38bcf9c94731b71a4d4cff5d68a3 | af27b78e89f07861ed28890008f17a65139d443c | "2022-09-06T06:45:13Z" | javascript | "2022-09-07T21:45:22Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 4,254 | ["docs/Guides/Ecosystem.md"] | Website build failure | ### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the issue has not already been raised
### Issue
Check out https://app.circleci.com/jobs/github/fastify/website/3103?utm_campaign=workflow-failed&utm_medium=email&utm_source=notification, this seems caused by
#4230. | https://github.com/fastify/fastify/issues/4254 | https://github.com/fastify/fastify/pull/4255 | a46aead95e1ce2de3928d376a39f79c9d1d5d2ca | 8073957fee3644f6b7b184d383c4ffed35c52307 | "2022-09-06T06:27:49Z" | javascript | "2022-09-06T06:40:25Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 4,221 | ["types/instance.d.ts", "types/route.d.ts"] | Does not work with TypeScript 4.8 | ### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the bug has not already been reported
### Fastify version
4.5.2
### Plugin version
_No response_
### Node.js version
16.17.0
### Operating system
macOS
### Operating system version (i.e. 20.04, 11.3, 10)
12.15.1
### Description
The fresh TypeScript 4.8 release is not compatible with Fastify's types.
Example:
```
node_modules/fastify/types/route.d.ts:48:98 - error TS2344: Type 'SchemaCompiler' does not satisfy the constraint 'FastifySchema'.
48 onRequest?: onRequestHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> | onRequestHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig,
SchemaCompiler, TypeProvider, Logger>[];
~~~~~~~~~~~~~~
node_modules/fastify/types/route.d.ts:27:3
27 SchemaCompiler = FastifySchema,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This type parameter might need an `extends FastifySchema` constraint.
```
/cc @fastify/typescript
### Steps to Reproduce
See https://github.com/SimenB/fastify-ts
### Expected Behavior
No type error | https://github.com/fastify/fastify/issues/4221 | https://github.com/fastify/fastify/pull/4222 | 1e5a62d30e654557419170ddceeaf902a9821b40 | cf29428ff7630877598de5fd4eea3ccf435e14b6 | "2022-08-26T09:07:04Z" | javascript | "2022-08-26T10:20:56Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 4,215 | ["docs/Reference/Server.md", "fastify.js", "lib/route.js", "test/has-route.test.js", "test/types/route.test-d.ts", "types/instance.d.ts"] | feature to check if route already exists | ### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the feature has not already been requested
### 🚀 Feature Proposal
It would be very useful if the Fastify instance exposes a method to check if a route is already registered in the current context just like it is implemented for content type parsers and constraints.
### Motivation
This feature could be useful for plugins to check if a certain route already exists and then add the route only if it does not yet exist in the current context.
### Example
```js
const fastify = require("fastify");
const app = fastify()
app.register(async (instance) => {
instance.get('/test', async () => { return 'firstInstance' })
instance.register(async (secondInstance) => {
if (!secondInstance.hasRoute('/test')) {
secondInstance.get('/test', async () => { return 'secondInstance' })
}
})
})
app.ready()
``` | https://github.com/fastify/fastify/issues/4215 | https://github.com/fastify/fastify/pull/4238 | fb682090f3236b870df53ddeff7e34f4c03b5f5e | c05f261584795dc0156045f9fe13fb52fdf810b0 | "2022-08-23T07:22:32Z" | javascript | "2022-09-04T13:21:12Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 4,207 | ["package.json", "test/async-await.test.js"] | "inject" doesn't respond when async route doesn't have a return statement | ### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the bug has not already been reported
### Fastify version
4.5.2
### Plugin version
_No response_
### Node.js version
16.16
### Operating system
Linux
### Operating system version (i.e. 20.04, 11.3, 10)
5.15.60-1-MANJARO
### Description
We've captured this issue while testing our async routes which don't have a `return` statement:
- Browser behavior is normal when accessing the route;
- `inject` method hangs while awaiting a response from the route;
### Steps to Reproduce
Create a Fastify server with a `GET` route to "/" with no `return` statement.
```
function buildServer() {
const fastify = require('fastify')()
fastify.get('/', async function (request, reply) {})
return fastify
}
```
- Build the server and notice how the route works in the Browser;
```
const server = buildServer()
server.listen({ port: 3000 })
```
- Invoke `inject` for the route;
```
async function testInject() {
const response = await server.inject({
method: 'GET',
url: '/'
})
console.log("expecting a response", response);
}
```
Notice how `console.log` is not reached, and the server hangs.
### Expected Behavior
If we omit `return` (or `reply.send({})`) the Browser still responds. But `inject` hangs.
We'd like to `inject` to have the same behavior as the browser, then we would be able to create async routes without `return` statements and/or non-async routes with no `reply.send({})` statements. | https://github.com/fastify/fastify/issues/4207 | https://github.com/fastify/fastify/pull/4211 | 54d3ccdcd2f65c337156c10117cb81ae0e5f2ed9 | 3d156e0ed1f5e28c013a7dd78532fedb65672185 | "2022-08-18T16:24:10Z" | javascript | "2022-08-22T12:20:20Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 4,204 | ["lib/fourOhFour.js", "test/404s.test.js"] | setErrorHandler is not called on plugin error | ### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the bug has not already been reported
### Fastify version
4.5.0
### Plugin version
4.2.0
### Node.js version
16.17.0
### Operating system
Linux
### Operating system version (i.e. 20.04, 11.3, 10)
22.04
### Description
Hi,
When I try to return an error from fastify plugin, I see that setErrorHandler is not called.
I don't know why because I call my error handler plugin before to register my new plugin.
Thanks for the help !
### Steps to Reproduce
- Go to https://github.com/flexper/fastify-auth-prisma
- run `pnpm dlx ts-node test/core/real.ts`
### Expected Behavior
Should return formated error from https://github.com/flexper/unify-fastify | https://github.com/fastify/fastify/issues/4204 | https://github.com/fastify/fastify/pull/4205 | 208d05b42b3240a6d2f6caf73f3296d85b6dfb0f | 3fd294dbe998fd687c1e8d3f059f1603f77c1edc | "2022-08-18T07:15:26Z" | javascript | "2022-08-18T14:18:52Z" |
closed | fastify/fastify | https://github.com/fastify/fastify | 4,148 | ["docs/Reference/Logging.md", "test/types/logger.test-d.ts", "test/types/request.test-d.ts", "types/logger.d.ts"] | Unable to use logger other than pino | ### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the issue has not already been raised
### Issue
I tried to update the fastify 3.28.0 to the version 4.2.1 and noticed that now it makes me to use pino logger. I used in previous version own logger class that fits fastify's interface.
Type of logger in fastify v4.2.1:
```
export type FastifyBaseLogger = pino.Logger & {
child(bindings: Bindings, options?: ChildLoggerOptions): FastifyBaseLogger
}
```
where pino.Logger is:
```
type Logger<Options = LoggerOptions> = BaseLogger & LoggerExtras<Options> & CustomLevelLogger<Options>;
```
so it requires that my logger must have all fields from LoggerExtras and CustomLevelLogger.
Regarding the code there is a [TODO](https://github.com/fastify/fastify/blob/0ca63a0819a154023c4de14e2723578a2b3f0961/types/logger.d.ts#L23) to use `pino.BaseLogger` instead of `pino.Logger`. Could we start using `pino.BaseLogger` or is there any significant issue that blocks us? | https://github.com/fastify/fastify/issues/4148 | https://github.com/fastify/fastify/pull/4150 | 18651e612d0aa14592bf3bac6a9e4a23116983f3 | 7870f23bd6f99f141b32a50994ccb3bc8aaf4ebb | "2022-07-20T07:09:27Z" | javascript | "2022-07-27T08:54:07Z" |