Gandalf does not rescue Bilbo and the dwarves in Chapter 2 ("The Shadow of the Past") of The Hobbit. Chapter 2 covers the dwarves' arrival at Bag End, Bilbo's recruitment, and their departure. The troll encounter—and Gandalf's rescue by tricking them until sunrise—occurs in Chapter 3, "Three Trolls."