[SalesForce] SalesforceDx: Can’t Authorise scratch Org

I am not able to authorize Scratch org in Force.com IDE 2. I am getting below error.
enter image description here

Detailed log is as below.

eclipse.buildId=unknown
java.version=1.8.0_131
java.vendor=Oracle Corporation
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=en_US
Command-line arguments: -os win32 -ws win32 -arch x86_64

com.salesforce.tools.ide.ui
Error
Sat Nov 04 14:15:02 IST 2017
Operation Failed

com.salesforce.tools.ide.cli.api.SfdxApiException: Cannot start the OAuth redirect server on port Error.

PortInUse: Cannot start the OAuth redirect server on port Error.
at ALMError (C:\Users\lapworld tech\AppData\Local\sfdx\client\node_modules\salesforce-alm\dist\lib\almError.js:35:19)
at _checkOsPort.then.catch (C:\Users\lapworld tech\AppData\Local\sfdx\client\node_modules\salesforce-alm\dist\lib\process.js:101:19)
at tryCatcher (C:\Users\lapworld tech\AppData\Local\sfdx\client\node_modules\bluebird\js\release\util.js:16:23)
at Promise._settlePromiseFromHandler (C:\Users\lapworld tech\AppData\Local\sfdx\client\node_modules\bluebird\js\release\promise.js:510:31)
at Promise._settlePromise (C:\Users\lapworld tech\AppData\Local\sfdx\client\node_modules\bluebird\js\release\promise.js:567:18)
at Promise._settlePromise0 (C:\Users\lapworld tech\AppData\Local\sfdx\client\node_modules\bluebird\js\release\promise.js:612:10)
at Promise._settlePromises (C:\Users\lapworld tech\AppData\Local\sfdx\client\node_modules\bluebird\js\release\promise.js:687:18)
at Async._drainQueue (C:\Users\lapworld tech\AppData\Local\sfdx\client\node_modules\bluebird\js\release\async.js:138:16)
at Async._drainQueues (C:\Users\lapworld tech\AppData\Local\sfdx\client\node_modules\bluebird\js\release\async.js:148:10)
at Immediate.Async.drainQueues (C:\Users\lapworld tech\AppData\Local\sfdx\client\node_modules\bluebird\js\release\async.js:17:14)
at runCallback (timers.js:781:20)
at tryOnImmediate (timers.js:743:5)
at processImmediate [as _immediateCallback] (timers.js:714:5)
at com.salesforce.tools.ide.cli.api.SfdxCommand.getSfdxApiException(SfdxCommand.java:205)
at com.salesforce.tools.ide.cli.api.SfdxCommand.processErrorOutput(SfdxCommand.java:254)
at com.salesforce.tools.ide.cli.api.SfdxCommand.executeCommand(SfdxCommand.java:168)
at com.salesforce.tools.ide.cli.api.WebLoginCommand.doCall(WebLoginCommand.java:49)
at com.salesforce.tools.ide.cli.api.WebLoginCommand.doCall(WebLoginCommand.java:1)
at com.salesforce.tools.ide.cli.api.SfdxCommand.call(SfdxCommand.java:114)
at com.salesforce.tools.ide.ui.internal.handlers.HandlerWithProgressDialog.executeInBackground(HandlerWithProgressDialog.java:60)
at com.salesforce.tools.ide.ui.internal.handlers.HandlerWithProgressDialog.lambda$0(HandlerWithProgressDialog.java:82)
at com.salesforce.tools.ide.ui.internal.parts.JobProgressMonitorDialog.lambda$0(JobProgressMonitorDialog.java:62)
at org.eclipse.core.runtime.jobs.Job$1.run(Job.java:161)

at org.eclipse.core.internal.jobs.Worker.run(Worker.java:56)

Note, I open the Org but can't authorize it.

Best Answer

The error indicates that the port is already in use. In order for a program to listen to a socket, it needs to bind to one of 65,635 ports. Only one copy of one program can use any particular port at one time. Odds are, a previous run started on the same port and never terminated, thus holding that port hostage. Try restarting your computer and then authorizing again. Otherwise, you might already have a program that runs on the default port (1717), in which case, you should create a new Connected App as outlined in Create a Connected App.

  1. Log in to your Dev Hub org.

  2. From Setup, enter App Manager in the Quick Find box to get to the Lightning Experience App Manager.

  3. In the top-right corner, click New Connected App.

  4. Update the basic information as needed, such as the connected app name and your email address.

  5. Select Enable OAuth Settings.

  6. For the callback URL, enter http://localhost:1717/OauthRedirect. If port 1717 (the default) is already in use on your local machine, specify an available one instead. Make sure to also update your sfdx-project.json file by setting the oauthLocalPort property to the new port. For example, if you set the callback URL to http://localhost:1919/OauthRedirect:

    "oauthLocalPort" : "1919"

(Note: Fixed a typo found in the original documentation)