Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: Azure/azure-functions-nodejs-library
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v4.6.0
Choose a base ref
...
head repository: Azure/azure-functions-nodejs-library
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v4.6.1
Choose a head ref
  • 4 commits
  • 5 files changed
  • 3 contributors

Commits on Dec 18, 2024

  1. Add build vulnerability scan (#317)

    * run vulnerability scan + testing
    
    * revert npm audit test
    
    ---------
    
    Co-authored-by: Victoria Hall <[email protected]>
    hallvictoria and Victoria Hall authored Dec 18, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    cc3613c View commit details

Commits on Jan 21, 2025

  1. Add port validation checks for HTTP streaming (#315)

    * basic working prototype
    
    * cleaner implementation
    
    * typing fixes + removed logs
    
    * removed logs
    
    * trying random port
    
    * port variables
    
    * checking only 25 ports
    
    ---------
    
    Co-authored-by: Victoria Hall <[email protected]>
    hallvictoria and Victoria Hall authored Jan 21, 2025

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    dd5912c View commit details

Commits on Jan 31, 2025

  1. Bump undici from 5.28.4 to 5.28.5 (#328)

    Bumps [undici](https://github.com/nodejs/undici) from 5.28.4 to 5.28.5.
    - [Release notes](https://github.com/nodejs/undici/releases)
    - [Commits](nodejs/undici@v5.28.4...v5.28.5)
    
    ---
    updated-dependencies:
    - dependency-name: undici
      dependency-type: direct:production
    ...
    
    Signed-off-by: dependabot[bot] <[email protected]>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Jan 31, 2025

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    e4fa901 View commit details

Commits on Feb 3, 2025

  1. update version to 4.6.1 (#329)

    hallvictoria authored Feb 3, 2025

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    d515a0a View commit details
Showing with 68 additions and 11 deletions.
  1. +2 −0 azure-pipelines/templates/build.yml
  2. +9 −8 package-lock.json
  3. +1 −1 package.json
  4. +1 −1 src/constants.ts
  5. +55 −1 src/http/httpProxy.ts
2 changes: 2 additions & 0 deletions azure-pipelines/templates/build.yml
Original file line number Diff line number Diff line change
@@ -16,6 +16,8 @@ jobs:
displayName: 'Install Node.js'
- script: npm ci
displayName: 'npm ci'
- script: npm audit --production
displayName: 'Run vulnerability scan'
- script: npm run updateVersion -- --buildNumber $(Build.BuildNumber)
displayName: 'npm run updateVersion'
condition: and(succeeded(), eq(${{ parameters.IsPrerelease }}, true))
17 changes: 9 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@azure/functions",
"version": "4.6.0",
"version": "4.6.1",
"description": "Microsoft Azure Functions NodeJS Framework",
"keywords": [
"azure",
2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License.

export const version = '4.6.0';
export const version = '4.6.1';

export const returnBindingKey = '$return';
56 changes: 55 additions & 1 deletion src/http/httpProxy.ts
Original file line number Diff line number Diff line change
@@ -4,13 +4,16 @@
import { serialize as serializeCookie } from 'cookie';
import { EventEmitter } from 'events';
import * as http from 'http';
import * as net from 'net';
import { AzFuncSystemError, ensureErrorType } from '../errors';
import { nonNullProp } from '../utils/nonNull';
import { workerSystemLog } from '../utils/workerSystemLog';
import { HttpResponse } from './HttpResponse';

const requests: Record<string, http.IncomingMessage> = {};
const responses: Record<string, http.ServerResponse> = {};
const minPort = 55000;
const maxPort = 55025;

const invocRequestEmitter = new EventEmitter();

@@ -105,8 +108,24 @@ export async function setupHttpProxy(): Promise<string> {

server.listen(() => {
const address = server.address();
// Valid address has been created
if (address !== null && typeof address === 'object') {
resolve(`http://localhost:${address.port}/`);
if (address.port === 0) {
// Auto-assigned port is 0, find and bind to an open port
workerSystemLog('debug', `Port 0 assigned. Finding open port.`);
findOpenPort((openPort: number) => {
// Close the server and re-listen on the found open port
server.close();
server.listen(openPort, () => {
workerSystemLog('debug', `Server is now listening on found open port: ${openPort}`);
});
resolve(`http://localhost:${openPort}/`);
});
} else {
// Auto-assigned port is not 0
workerSystemLog('debug', `Auto-assigned port is valid. Port: ${address.port}`);
resolve(`http://localhost:${address.port}/`);
}
} else {
reject(new AzFuncSystemError('Unexpected server address during http proxy setup'));
}
@@ -117,3 +136,38 @@ export async function setupHttpProxy(): Promise<string> {
});
});
}

// Function to find an open port starting from a specified port
function findOpenPort(callback: (port: number) => void): void {
const server = net.createServer();

function tryPort(port: number) {
if (port > maxPort) {
// If we've reached the maximum port, throw an error
throw new AzFuncSystemError(
`No available ports found between ${minPort} and ${maxPort}. To enable HTTP streaming, please open a port in this range.`
);
}

server.once('error', () => {
// If the port is unavailable, increment and try the next one
tryPort(port + 1);
});

// If the port is available, return it
server.once('listening', () => {
const address = server.address();
if (address !== null && typeof address === 'object') {
port = address.port;
server.close();
callback(port);
}
});

// Try binding to the given port
server.listen(port);
}

// Start trying from the specified starting port
tryPort(minPort);
}